amxmodx/plugins/include/celltrie.inc

234 lines
6.6 KiB
PHP
Raw Normal View History

// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
2008-04-14 23:52:11 +04:00
#if defined _celltrie_included
2014-05-03 15:22:48 +04:00
#endinput
2008-04-14 23:52:11 +04:00
#endif
#define _celltrie_included
enum Trie
{
Invalid_Trie = 0
};
2014-05-04 01:21:56 +04:00
enum Snapshot
{
Invalid_Snapshot = 0
};
2014-05-03 15:22:48 +04:00
/**
* Creates a hash map. A hash map is a container that can map strings (called
* "keys") to arbitrary values (cells, arrays, or strings). Keys in a hash map
* are unique. That is, there is at most one entry in the map for a given key.
*
* Insertion, deletion, and lookup in a hash map are all considered to be fast
* operations, amortized to O(1), or constant time.
*
* The word "Trie" in this API is historical. As of AMX Mod X 1.8.3, tries have
* been internally replaced with hash tables, which have O(1) insertion time
* instead of O(n).
*
2014-05-04 01:50:43 +04:00
* @return New Map handle, which must be freed via TrieDestroy().
2014-05-03 15:22:48 +04:00
*/
2008-04-14 23:52:11 +04:00
native Trie:TrieCreate();
2014-05-03 15:22:48 +04:00
/**
* Clears all entries from a Map.
*
2014-05-04 01:50:43 +04:00
* @param handle Map handle.
2014-05-03 15:22:48 +04:00
*
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
2014-05-03 15:22:48 +04:00
*/
2008-04-14 23:52:11 +04:00
native TrieClear(Trie:handle);
2014-05-03 15:22:48 +04:00
/**
* Sets a value in a hash map, either inserting a new entry or replacing an old one.
*
2014-05-04 01:50:43 +04:00
* @param handle Map handle.
2014-05-03 15:22:48 +04:00
* @param key Key string.
* @param value Value to store at this key.
* @param replace If false, operation will fail if the key is already set.
2014-05-03 15:22:48 +04:00
*
* @return True on success, false on failure.
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
2014-05-03 15:22:48 +04:00
*/
native TrieSetCell(Trie:handle, const key[], any:value, bool:replace = true);
2014-05-03 15:22:48 +04:00
/**
* Sets a string value in a Map, either inserting a new entry or replacing an old one.
*
2014-05-04 01:50:43 +04:00
* @param handle Map handle.
2014-05-03 15:22:48 +04:00
* @param key Key string.
* @param value String to store.
* @param replace If false, operation will fail if the key is already set.
2014-05-03 15:22:48 +04:00
*
* @return True on success, false on failure.
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
2014-05-03 15:22:48 +04:00
*/
native TrieSetString(Trie:handle, const key[], const value[], bool:replace = true);
2014-05-03 15:22:48 +04:00
/**
* Sets an array value in a Map, either inserting a new entry or replacing an old one.
*
2014-05-04 01:50:43 +04:00
* @param handle Map handle.
2014-05-03 15:22:48 +04:00
* @param key Key string.
* @param buffer Array to store.
* @param size Number of items in the array.
* @param replace If false, operation will fail if the key is already set.
2014-05-03 15:22:48 +04:00
*
* @return True on success, false on failure.
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
* Invalid array size.
2014-05-03 15:22:48 +04:00
*/
native TrieSetArray(Trie:handle, const key[], const any:buffer[], size, bool:replace = true);
2008-04-14 23:52:11 +04:00
2014-05-03 15:22:48 +04:00
/**
* Retrieves a value in a Map.
*
2014-05-04 01:50:43 +04:00
* @param handle Map handle.
2014-05-03 15:22:48 +04:00
* @param key Key string.
* @param value Variable to store value.
2014-05-04 01:50:43 +04:00
* @return True on success. False if the key is not set, or the key is set
2014-05-03 15:22:48 +04:00
* as an array or string (not a value).
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
2014-05-03 15:22:48 +04:00
*/
2008-04-14 23:52:11 +04:00
native bool:TrieGetCell(Trie:handle, const key[], &any:value);
2014-05-03 15:22:48 +04:00
/**
* Retrieves a string in a Map.
*
2014-05-04 01:50:43 +04:00
* @param handle Map handle.
2014-05-03 15:22:48 +04:00
* @param key Key string.
* @param output Buffer to store value.
* @param outputsize Maximum size of string buffer.
* @param size Optional parameter to store the number of bytes written to the buffer.
2014-05-03 15:22:48 +04:00
*
2014-05-04 01:50:43 +04:00
* @return True on success. False if the key is not set, or the key is set
2014-05-03 15:22:48 +04:00
* as a value or array (not a string).
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
* Invalid buffer size.
2014-05-03 15:22:48 +04:00
*/
native bool:TrieGetString(Trie:handle, const key[], output[], outputsize, &size = 0);
2014-05-03 15:22:48 +04:00
/**
* Retrieves an array in a Map.
*
2014-05-04 01:50:43 +04:00
* @param handle Map handle.
2014-05-03 15:22:48 +04:00
* @param key Key string.
* @param output Buffer to store array.
* @param outputsize Maximum size of array buffer.
* @param size Optional parameter to store the number of elements written to the buffer.
2014-05-03 15:22:48 +04:00
*
2014-05-04 01:50:43 +04:00
* @return True on success. False if the key is not set, or the key is set
2014-05-03 15:22:48 +04:00
* as a value or string (not an array).
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
* Invalid array size.
2014-05-03 15:22:48 +04:00
*/
native bool:TrieGetArray(Trie:handle, const key[], any:output[], outputsize, &size = 0);
2008-04-14 23:52:11 +04:00
2014-05-03 15:22:48 +04:00
/**
* Removes a key entry from a Map.
*
2014-05-04 01:50:43 +04:00
* @param handle Map handle.
2014-05-03 15:22:48 +04:00
* @param key Key string.
*
* @return True on success, false if the value was never set.
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
2014-05-03 15:22:48 +04:00
*/
2008-04-14 23:52:11 +04:00
native bool:TrieDeleteKey(Trie:handle, const key[]);
2014-05-03 15:22:48 +04:00
/**
* Checks a key entry existence from a Map.
*
2014-05-04 01:50:43 +04:00
* @param handle Map handle.
2014-05-03 15:22:48 +04:00
* @param key Key string.
*
* @return True on success, false if the value was never set.
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
2014-05-03 15:22:48 +04:00
*/
2008-04-14 23:52:11 +04:00
native bool:TrieKeyExists(Trie:handle, const key[]);
2014-05-03 15:22:48 +04:00
/**
* Destroys a Map.
*
2014-05-04 01:50:43 +04:00
* @param handle Map handle.
2014-05-03 15:22:48 +04:00
*
* @return True on success, false if the value was never set.
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
2014-05-03 15:22:48 +04:00
*/
2008-04-14 23:52:11 +04:00
native TrieDestroy(&Trie:handle);
2014-05-03 18:09:31 +04:00
/**
* Retrieves the number of elements in a map.
*
2014-05-04 01:50:43 +04:00
* @param handle Map handle.
2014-05-03 18:09:31 +04:00
*
* @return Number of elements in the trie.
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
2014-05-03 18:09:31 +04:00
*/
native TrieGetSize(Trie:handle);
2014-05-04 01:21:56 +04:00
/**
* Creates a snapshot of all keys in the map. If the map is changed after this
* call, the changes are not reflected in the snapshot. Keys are not sorted.
*
* @param handle Map handle.
*
* @return New map snapshot handle, which must be freed via TrieSnapshotDestroy().
* @error Invalid handle.
*/
native Snapshot:TrieSnapshotCreate(Trie:handle);
/**
* Returns the number of keys in a map snapshot. Note that this may be
* different from the size of the map, since the map can change after the
* snapshot of its keys was taken.
*
* @param handle Map snapshot.
*
* @return Number of keys.
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
2014-05-04 01:21:56 +04:00
*/
native TrieSnapshotLength(Snapshot:handle);
/**
* Returns the buffer size required to store a given key. That is, it returns
* the length of the key plus one.
*
* @param handle Map snapshot.
* @param index Key index (starting from 0).
*
* @return Buffer size required to store the key string.
2014-05-04 01:50:43 +04:00
* @error Invalid handle or index out of range.
2014-05-04 01:21:56 +04:00
*/
native TrieSnapshotKeyBufferSize(Snapshot:handle, index);
/**
* Retrieves the key string of a given key in a map snapshot.
*
* @param handle Map snapshot.
* @param index Key index (starting from 0).
* @param buffer String buffer.
* @param maxlength Maximum buffer length.
*
* @return Number of bytes written to the buffer.
2014-05-04 01:50:43 +04:00
* @error Invalid handle or index out of range.
2014-05-04 01:21:56 +04:00
*/
native TrieSnapshotGetKey(Snapshot:handle, index, buffer[], maxlength);
/**
* Destroys a Map snapshot
*
* @param handle Map snapshot.
*
* @return True on success, false if the value was never set.
2014-05-04 01:50:43 +04:00
* @error Invalid handle.
2014-05-04 01:21:56 +04:00
*/
native TrieSnapshotDestroy(&Snapshot:handle);