View Single Post
kossolax
AlliedModders Donor
Join Date: Jan 2008
Location: Belgium
Old 03-31-2021 , 07:24   Re: [INC] Queue - FIFO
Reply With Quote #7

Quote:
Originally Posted by JoinedSenses View Post
SM doesnt have LinkedList
This is not tested, but would be more smart for O(1) push & pop at the cost of some more memory usage (using circular buffer)


PHP Code:
methodmap Queue Handle {
    public 
Queue(int size=32) {
        
ArrayList data = new ArrayList(1size+3);
        
data.Set(00);        // tail
        
data.Set(10);        // head
        
data.Set(2size);    // Size
        
return view_as<Queue>(data);
    }
    
    
property int Tail {
        public 
get() { return view_as<ArrayList>(this).Get(0); }
        public 
set(const int value) { view_as<ArrayList>(this).Set(0value); }
    }
    
property int Head {
        public 
get() { return view_as<ArrayList>(this).Get(1); }
        public 
set(const int value) { view_as<ArrayList>(this).Set(1value); }
    }
    
property int Size {
        public 
get() { return view_as<ArrayList>(this).Get(2); }
    }
    
// ----
    
property bool isEmpty {
        public 
get() { return this.Head == this.Tail; }
    }
    
property bool isFull {
        public 
get() { return ((this.Head+1)%this.Size) == this.Tail; }
    }
    
// ----
    
public void Push(const int value) {
        
view_as<ArrayList>(this).Set(this.Head+3value);
        
this.Head = (this.Head 1) % this.Size;
    }
    public 
int Pop() {
        
int tmp view_as<ArrayList>(this).Get(this.Tail+3);
        
this.Tail = (this.Tail 1) % this.Size;
        return 
tmp;
    }
    public 
int Front() {
        return 
view_as<ArrayList>(this).Get(this.Tail+3);
    }


Last edited by kossolax; 03-31-2021 at 07:48.
kossolax is offline