plugins/include/adt_trie.inc
author Scott Ehlert <ds@alliedmods.net>
Fri Apr 11 17:16:36 2008 +0000 (2008-04-11)
changeset 1990 de135d1f05b1
parent 1952 b7aa2b626807
child 2023 1bd756a9f8db
permissions -rw-r--r--
Added more missing svn:keywords properties to some files (this should be the last of them before I never have to do this again)
Moved sm_memtable files in sqlite extension to sdk directory (to be consistent with topmenus)
Some extension source files had an incorrect extension name in their headers
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     5
 * =============================================================================
ds@1952
     6
 *
ds@1952
     7
 * This file is part of the SourceMod/SourcePawn SDK.
ds@1952
     8
 *
ds@1952
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    11
 * Free Software Foundation.
ds@1952
    12
 * 
ds@1952
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    16
 * details.
ds@1952
    17
 *
ds@1952
    18
 * You should have received a copy of the GNU General Public License along with
ds@1952
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    20
 *
ds@1952
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    28
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    29
 *
ds@1952
    30
 * Version: $Id$
ds@1952
    31
 */
ds@1952
    32
 
ds@1952
    33
#if defined _adt_trie_included
ds@1952
    34
 #endinput
ds@1952
    35
#endif
ds@1952
    36
#define _adt_trie_included
ds@1952
    37
ds@1952
    38
/**
ds@1952
    39
 * Creates a Trie structure.  A trie is a data storage object that maps any value to a 
ds@1952
    40
 * string of text.  It features very fast lookup and deletion, but grows very slow for 
ds@1952
    41
 * insertion once tens of thousands of items are added.
ds@1952
    42
 *
ds@1952
    43
 * Keys in Tries are unique.  That is, each key may only have one value.  Unlike arrays, 
ds@1952
    44
 * Tries cannot be iterated right now.  Since the contents are known to be unique, to 
ds@1952
    45
 * work around this, you can use ADT Arrays to store a list of keys known to be in a 
ds@1952
    46
 * Trie.
ds@1952
    47
 *
ds@1952
    48
 * @return 			New Trie Handle, which must be freed via CloseHandle().
ds@1952
    49
 */
ds@1952
    50
native Handle:CreateTrie();
ds@1952
    51
ds@1952
    52
/**
ds@1952
    53
 * Sets a value in a Trie, either inserting a new entry or replacing an old one.
ds@1952
    54
 *
ds@1952
    55
 * @param trie		Trie Handle.
ds@1952
    56
 * @param key		Key string.
ds@1952
    57
 * @param value		Value to store at this key.
ds@1952
    58
 * @param replace	If false, operation will fail if the key is already set.
ds@1952
    59
 * @return			True on success, false on failure.
ds@1952
    60
 * @error			Invalid Handle.
ds@1952
    61
 */
ds@1952
    62
native bool:SetTrieValue(Handle:trie, const String:key[], any:value, bool:replace=true);
ds@1952
    63
ds@1952
    64
/**
ds@1952
    65
 * Sets an array value in a Trie, either inserting a new entry or replacing an old one.
ds@1952
    66
 *
ds@1952
    67
 * @param trie		Trie Handle.
ds@1952
    68
 * @param key		Key string.
ds@1952
    69
 * @param array		Array to store.
ds@1952
    70
 * @param num_items	Number of items in the array.
ds@1952
    71
 * @param replace	If false, operation will fail if the key is already set.
ds@1952
    72
 * @return			True on success, false on failure.
ds@1952
    73
 * @error			Invalid Handle.
ds@1952
    74
 */
ds@1952
    75
native bool:SetTrieArray(Handle:trie, const String:key[], const array[], num_items, bool:replace=true);
ds@1952
    76
ds@1952
    77
/**
ds@1952
    78
 * Sets a string value in a Trie, either inserting a new entry or replacing an old one.
ds@1952
    79
 *
ds@1952
    80
 * @param trie		Trie Handle.
ds@1952
    81
 * @param key		Key string.
ds@1952
    82
 * @param array		Array to store.
ds@1952
    83
 * @param num_items	Number of items in the array.
ds@1952
    84
 * @param replace	If false, operation will fail if the key is already set.
ds@1952
    85
 * @return			True on success, false on failure.
ds@1952
    86
 * @error			Invalid Handle.
ds@1952
    87
 */
ds@1952
    88
native bool:SetTrieString(Handle:trie, const String:key[], const String:value[], bool:replace=true);
ds@1952
    89
ds@1952
    90
/**
ds@1952
    91
 * Retrieves a value in a Trie.
ds@1952
    92
 *
ds@1952
    93
 * @param trie		Trie Handle.
ds@1952
    94
 * @param key		Key string.
ds@1952
    95
 * @param val		Variable to store value.
ds@1952
    96
 * @return			True on success.  False if the key is not set, or the key is set 
ds@1952
    97
 *					as an array or string (not a value).
ds@1952
    98
 * @error			Invalid Handle.
ds@1952
    99
 */
ds@1952
   100
native bool:GetTrieValue(Handle:trie, const String:key[], &any:value);
ds@1952
   101
ds@1952
   102
/**
ds@1952
   103
 * Retrieves an array in a Trie.
ds@1952
   104
 *
ds@1952
   105
 * @param trie		Trie Handle.
ds@1952
   106
 * @param key		Key string.
ds@1952
   107
 * @param array		Buffer to store array.
ds@1952
   108
 * @param max_size	Maximum size of array buffer.
ds@1952
   109
 * @param size		Optional parameter to store the number of elements written to the buffer.
ds@1952
   110
 * @return			True on success.  False if the key is not set, or the key is set 
ds@1952
   111
 *					as a value or string (not an array).
ds@1952
   112
 * @error			Invalid Handle.
ds@1952
   113
 */
ds@1952
   114
native bool:GetTrieArray(Handle:trie, const String:key[], array[], max_size, &size=0);
ds@1952
   115
ds@1952
   116
/**
ds@1952
   117
 * Retrieves a string in a Trie.
ds@1952
   118
 *
ds@1952
   119
 * @param trie		Trie Handle.
ds@1952
   120
 * @param key		Key string.
ds@1952
   121
 * @param value		Buffer to store value.
ds@1952
   122
 * @param max_size	Maximum size of string buffer.
ds@1952
   123
 * @param size		Optional parameter to store the number of bytes written to the buffer.
ds@1952
   124
 * @return			True on success.  False if the key is not set, or the key is set 
ds@1952
   125
 *					as a value or array (not a string).
ds@1952
   126
 * @error			Invalid Handle.
ds@1952
   127
 */
ds@1952
   128
native bool:GetTrieString(Handle:trie, const String:key[], String:value[], max_size, &size=0);
ds@1952
   129
ds@1952
   130
/**
ds@1952
   131
 * Removes a key entry from a Trie.
ds@1952
   132
 *
ds@1952
   133
 * @param trie		Trie Handle.
ds@1952
   134
 * @param key		Key string.
ds@1952
   135
 * @return			True on success, false if the value was never set.
ds@1952
   136
 * @error			Invalid Handle.
ds@1952
   137
 */
ds@1952
   138
native RemoveFromTrie(Handle:trie, const String:key[]);
ds@1952
   139
ds@1952
   140
/**
ds@1952
   141
 * Clears all entries from a Trie.
ds@1952
   142
 *
ds@1952
   143
 * @param trie		Trie Handle.
ds@1952
   144
 * @error			Invalid Handle.
ds@1952
   145
 */
ds@1952
   146
native ClearTrie(Handle:trie);
ds@1952
   147
ds@1952
   148
/**
ds@1952
   149
 * Retrieves the number of elements in a trie.
ds@1952
   150
 *
ds@1952
   151
 * Note that trie items are not enumerable/iteratable.  If you need to 
ds@1952
   152
 * retrieve the elements in a trie, store its keys in an ADT Array. 
ds@1952
   153
 *
ds@1952
   154
 * @param trie		Trie Handle.
ds@1952
   155
 * @return			Number of elements in the trie.
ds@1952
   156
 * @error			Invalid Handle.
ds@1952
   157
 */
ds@1952
   158
native GetTrieSize(Handle:trie);