• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] What Data Structure Is This?

Status
Not open for further replies.
So, I was trying to code a Dequeue and I can't think of how to do it. Then I came up to this idea:
JASS:
module UnknownFields
    readonly thistype front
    readonly thistype back
endmodule

module UnknownPushFront
    implement UnknownFields
    static method pushFront takes thistype node returns nothing
        set thistype(0).front.back = node
        set node.front = thistype(0).front
        set thistype(0).front = node
    endmethod
endmodule

module UnknownPushBack
    implement UnknownFields
    static method pushBack takes thistype node returns nothing
        set thistype(0).back.front = node
        set node.back = thistype(0).back
        set thistype(0).back = node
    endmethod
endmodule

module UnknownPopFront
    implement UnknownFields
    static method popFront takes nothing returns thistype
        local thistype node = thistype(0).front
        set thistype(0).front = node.front
        set thistype(0).front.back = 0
        return node
    endmethod
endmodule

module UnknownPopBack
    implement UnknownFields
    static method popBack takes nothing returns thistype
        local thistype node = thistype(0).back
        set thistype(0).back = node.back
        set thistype(0).back.front = 0
        return node
    endmethod
endmodule

module UnknownPush
    implement UnknownPushFront
    implement UnknownPushBack
endmodule

module UnknownPop
    implement UnknownPopFront
    implement UnknownPopBack
endmodule

module UnknownClear
    implement UnknownFields
    
    static method clear takes nothing returns nothing
        set thistype(0).front = 0
        set thistype(0).back = 0
    endmethod
endmodule

module Unknown
    implement UnknownPush
    implement UnknownPop
    implement UnknownClear
endmodule

Demo code:
JASS:
struct Hello extends array

    implement Unknown
    static method onInit takes nothing returns nothing
        local thistype i = 1
        call pushFront(i)
        set i = i + 1
        call pushFront(i)
        set i = i + 1
        call pushFront(i)
        set i = i + 1
        call pushFront(i)
        set i = i + 1
        call pushBack(i)
        set i = i + 1
        call pushBack(i)
        set i = i + 1
        call pushBack(i)
        set i = i + 1
        call pushBack(i)
        call BJDebugMsg(I2S(popFront()))
        call BJDebugMsg(I2S(popFront()))
        call BJDebugMsg(I2S(popFront()))
        call BJDebugMsg(I2S(popFront()))
        call BJDebugMsg(I2S(popBack()))
        call BJDebugMsg(I2S(popBack()))
        call BJDebugMsg(I2S(popBack()))
        call BJDebugMsg(I2S(popBack()))
    endmethod
endstruct
Its not a Dequeue(i guess)
Its a double-ended structure,both grows in each end(Front and Back).
It works like a Stack,which retrieves the last node to the first node or first node to the last node operation.

Does anybody knows this data structure?
 
Last edited:
Assuming your code works, it is.

A deque is a double-ended queue that allows insertion and deletion on both ends.
The operations are enqueue and dequeue.

FIFO and LIFO are not applicable here. You can push to the back and pop from the front or push to the back and pop from the back too.

Some deque implementations can be I/O restricted on any one of the ends. Not both however. Else, you have a useless piece of shit code that does nothing. That's the only classification for deques.

In your case, you have no I/O restrictions.
 
I already told you, it's a deque.

Meh. It doesn't use the FIFO and LILO operation.

Deque -> double-ended queue.
Dequeue -> removing an element from the queue.

Do we really need such data structures in Warcraft III though? Or are you just coding them because you can?
Sorry but it is:
Dequeue - Double-ended queue
Pop - removing a node from a queue.
 
Enqueue = push node on the queue/deque
Dequeue = pop node off the queue/deque

No direction is specified.

Pop is an operation on a stack. You can say pop for a queue, but that's not consistent with standard naming.
Push is also valid, but still inconsistent.

Meh. It doesn't use the FIFO and LILO operation.

That's because it's a deque.
Your deque implementation is not I/O restricted on any of the directions, so you can't really classify it as FIFO or FILO.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
You can get a "FIFO queue" which is what people usually think of as a queue but also a "FILO queue" but those are commonly referred to as stacks.

A stack is specifically FILO queue so there is no need to ever mention FILO queue outside of education purposes. As such one can assume that every queue by itself is a FIFO queue.

The reason FIFO and FILO queues exist is because often 1-2 small changes to an algorithm is all that is required to convert between the them. These changes could come in the form of a switch defined at initialization where a constant term such as FIFO and FILO could be used to specify the behaviour. The fact remains that FILO queues behave as stacks while the term queue comes from a more practical approach such as a queue at a checkout which is FIFO.
 
Status
Not open for further replies.
Top