2007-01-25 23:36:38 +01:00
|
|
|
/**
|
2007-03-22 22:50:20 +01:00
|
|
|
* vim: set ts=4 :
|
2007-08-15 08:19:30 +02:00
|
|
|
* =============================================================================
|
2007-08-01 04:12:47 +02:00
|
|
|
* SourceMod
|
2008-03-27 05:54:56 +01:00
|
|
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
2007-08-15 08:19:30 +02:00
|
|
|
* =============================================================================
|
2007-01-25 23:36:38 +01:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
2007-08-01 04:12:47 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* 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.
|
2007-08-01 04:12:47 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-08-01 04:12:47 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
2007-01-25 23:36:38 +01:00
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
2006-12-06 00:52:43 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2007-08-29 07:22:47 +02:00
|
|
|
#include <sm_trie_tpl.h>
|
2006-12-06 00:52:43 +01:00
|
|
|
#include "sm_trie.h"
|
|
|
|
|
|
|
|
struct Trie
|
|
|
|
{
|
2007-08-29 07:20:48 +02:00
|
|
|
KTrie<void *> k;
|
2006-12-06 00:52:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Trie *sm_trie_create()
|
|
|
|
{
|
2007-08-29 07:20:48 +02:00
|
|
|
return new Trie;
|
2007-01-24 22:51:49 +01:00
|
|
|
}
|
|
|
|
|
2006-12-06 00:52:43 +01:00
|
|
|
void sm_trie_destroy(Trie *trie)
|
|
|
|
{
|
2006-12-07 20:10:26 +01:00
|
|
|
delete trie;
|
2006-12-06 00:52:43 +01:00
|
|
|
}
|
|
|
|
|
2007-08-29 07:20:48 +02:00
|
|
|
bool sm_trie_insert(Trie *trie, const char *key, void *value)
|
2006-12-15 14:38:04 +01:00
|
|
|
{
|
2007-08-29 07:20:48 +02:00
|
|
|
return trie->k.insert(key, value);
|
2007-08-29 04:37:25 +02:00
|
|
|
}
|
2006-12-15 14:38:04 +01:00
|
|
|
|
2007-08-29 07:20:48 +02:00
|
|
|
bool sm_trie_replace(Trie *trie, const char *key, void *value)
|
2007-08-29 04:37:25 +02:00
|
|
|
{
|
2007-08-29 07:20:48 +02:00
|
|
|
return trie->k.replace(key, value);
|
2006-12-15 14:38:04 +01:00
|
|
|
}
|
|
|
|
|
2006-12-06 00:52:43 +01:00
|
|
|
bool sm_trie_retrieve(Trie *trie, const char *key, void **value)
|
|
|
|
{
|
2007-08-29 07:20:48 +02:00
|
|
|
void **pValue = trie->k.retrieve(key);
|
|
|
|
|
|
|
|
if (!pValue)
|
2006-12-06 00:52:43 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
{
|
2007-08-29 07:20:48 +02:00
|
|
|
*value = *pValue;
|
2006-12-06 00:52:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-08-29 07:20:48 +02:00
|
|
|
bool sm_trie_delete(Trie *trie, const char *key)
|
2006-12-06 00:52:43 +01:00
|
|
|
{
|
2007-08-29 07:20:48 +02:00
|
|
|
return trie->k.remove(key);
|
2006-12-06 00:52:43 +01:00
|
|
|
}
|
2007-07-08 05:17:29 +02:00
|
|
|
|
2007-08-29 07:20:48 +02:00
|
|
|
void sm_trie_clear(Trie *trie)
|
2007-07-08 05:17:29 +02:00
|
|
|
{
|
2007-08-29 07:20:48 +02:00
|
|
|
trie->k.clear();
|
2007-07-08 05:17:29 +02:00
|
|
|
}
|
2007-12-05 19:07:18 +01:00
|
|
|
|
|
|
|
size_t sm_trie_mem_usage(Trie *trie)
|
|
|
|
{
|
|
|
|
return trie->k.mem_usage();
|
|
|
|
}
|