Created
April 18, 2020 20:34
-
-
Save michicc/5acb643e2e824666aab5b491d0cd4662 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Simply using AIList of indexes is faster than any squirrel implementation. | |
*/ | |
class Native_Heap | |
{ | |
_queue = null; | |
_sorter = null; | |
constructor() | |
{ | |
_queue = []; | |
_sorter = AIPriorityQueue(); | |
} | |
/** | |
* Insert a new entry in the list. | |
* The complexity of this operation is UNKNOWN | |
* @param item The item to add to the list. | |
* @param priority The priority this item has. | |
*/ | |
function Insert(item, priority); | |
/** | |
* Pop the first entry of the list. | |
* This is always the item with the lowest priority. | |
* The complexity of this operation is UNKNOWN | |
* @return The item of the entry with the lowest priority. | |
*/ | |
function Pop(); | |
/** | |
* Peek the first entry of the list. | |
* This is always the item with the lowest priority. | |
* The complexity of this operation is UNKNOWN | |
* @return The item of the entry with the lowest priority. | |
*/ | |
function Peek(); | |
/** | |
* Get the amount of current items in the list. | |
* The complexity of this operation is UNKNOWN | |
* @return The amount of items currently in the list. | |
*/ | |
function Count(); | |
/** | |
* Check if an item exists in the list. | |
* The complexity of this operation is UNKNOWN | |
* @param item The item to check for. | |
* @return True if the item is already in the list. | |
*/ | |
function Exists(item); | |
}; | |
function Native_Heap::Insert(item, priority) | |
{ | |
_queue.push(item); | |
_sorter.Insert(_queue.len() - 1, priority); | |
} | |
function Native_Heap::Pop() | |
{ | |
if (_sorter.IsEmpty()) return null; | |
local ret = _sorter.Pop(); | |
return _queue[ret]; | |
} | |
function Native_Heap::Peek() | |
{ | |
if (_sorter.IsEmpty()) return null; | |
return _queue[_sorter.Peek()]; | |
} | |
function Native_Heap::Count() | |
{ | |
return _sorter.Count(); | |
} | |
function Native_Heap::Exists(item) | |
{ | |
return false; /* WRONG!!! */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment