Jump to content
code34

OO_QUEUE - PRIORITY QUEUE

Recommended Posts

OO_QUEUE - PRIORITY QUEUE
Lastest version: 0.3 by Code34
 



Download from : DropBox
Like to Donate ? Donate with paypal


Github: https://github.com/code34/oo_queue.vr
Reference: http://forums.bistudio.com/showthread.php?167980-Object-Oriented-SQF-Scripting-and-Compiling

 

 



Description
In computer science, a priority queue is an abstract data type which is like a regular queue or stack data structure, but where additionally each element has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority. If two elements have the same priority, they are served according to their order in the queue (source: wikipedia)


Features
    Add element in a priority queue according a priority
    Get the first element in the queue according its priority


 Applications
     Bandwidth management
    Discrete event simulation
    Dijkstra's algorithm
    Huffman coding
    Best-first search algorithms
    ROAM triangulation algorithm
    Prim's algorithm for minimum spanning tree


Licence
Under Gpl, you can share, modify, distribute this script but don't remove the licence and the name of the original author

 

 

 

Example

 

 

Quote

 

        call compilefinal preprocessFileLineNumbers "oo_queue.sqf";

         _queue = ["new", ""] call OO_QUEUE;

        ["put", [4, "JOHN"]] call _queue;    
        ["put", [4, "OLIVIER"]] call _queue;
        ["put", [3, "NICOLAS"]] call _queue;
        ["put", [3, "SOPHIE"]] call _queue;
        ["put", [1, "ANTOINE"]] call _queue;
        ["put", [2, "JP"]] call _queue;
        ["put", [2, "MIMI"]] call _queue;
        ["put", [6, "DARKVADOR"]] call _queue;

        sleep 2;
        
        while { !("isEmpty" call _queue) } do {
            hint format ["next element : %1",  ["get", ""] call _queue];
            sleep 1;
        };

        hint "empty!";

 

 

Documentation

Quote


    Author: code34 nicolas_boiteux@yahoo.fr
    Copyright (C) 2016-2018 Nicolas BOITEUX

    CLASS OO_QUEUE
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    --------------------------------------------------------------------------------------------------------------

    Function:  _queue = ["new", ""] call OO_QUEUE;
    Create a new Priority queue object
        
    Parameters: nothing
    Return : _queue : OO_QUEUE object

    --------------------------------------------------------------------------------------------------------------

    Function: _array = "toArray" call _queue;
    Return an array containing all the elements of the queue
        
    Parameters: nothing
    Return : _array : array

    --------------------------------------------------------------------------------------------------------------

    Function: "clearQueue" call _queue;
    Removes all of the elements from this priority queue
        
    Parameters: nothing
    Return : nothing

    --------------------------------------------------------------------------------------------------------------

    Function: _bool = "isEmpty" call _queue;
    Test if the priority queue is empty
        
    Parameters: nothing
    Return : _bool : boolean

    --------------------------------------------------------------------------------------------------------------

    Function: _count = "count" call _queue;
    Count the number of elements in the Queue
        
    Parameters: nothing
    Return : _count : scalar

    --------------------------------------------------------------------------------------------------------------

    Function: _element = "get"  call _queue;
    Get next first in element according its priority, and remove it
    
    Return :
        element : according the type of element in the queue
        or if queue is empty : return nil

    --------------------------------------------------------------------------------------------------------------

    Function: _bool = ["put", _array] call _queue;
    Insert an element in priority queue according its priority
    
    Parameters : _array : [_priority, _element]
        1 - priority - (0 highest priority) - scalar
         2 - Element to insert in the queue - can be ANY type (ex: STRING, SCALAR, ARRAY, OBJECT, etc)
    
    Return : boolean, if success

    --------------------------------------------------------------------------------------------------------------
    
    Function:  ["delete", _template] call OO_TEMPLATE;
    Destroy the template object
        
    Parameters:
        object - template object
    
    Return : nothing

Readme

Quote

    /*
    Author: code34 nicolas_boiteux@yahoo.fr
    Copyright (C) 2016-2018 Nicolas BOITEUX

    CLASS OO_QUEUE
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */

    Create a main bus message between clients & server
    
    Usage:
        put the "oo_queue.sqf" and the "oop.h" files in your mission directory
        put this code into your mission init.sqf
        call compile preprocessFileLineNumbers "oo_queue.sqf";

    See example mission in directory: init.sqf
    
    Licence:
    You can share, modify, distribute this script but don't remove the licence and the name of the original author

    logs:
        0.3    - add unit tests, performance improvement - Killzone kid optimization
        0.2    - private keyword, performance improvement
        0.1     - OO QUEUE - first release

Share this post


Link to post
Share on other sites

Hi Foxhound !

 

you are my best follower :) always at the top, first in the place <3

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×