Add new trie native: ContainsKey() (#1390)
This commit is contained in:
parent
0caa349f6a
commit
a191a907e9
@ -350,6 +350,27 @@ static cell_t SetTrieString(IPluginContext *pContext, const cell_t *params)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell_t ContainsKeyInTrie(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
CellTrie *pTrie;
|
||||||
|
HandleError err;
|
||||||
|
HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent);
|
||||||
|
|
||||||
|
Handle_t hndl = params[1];
|
||||||
|
|
||||||
|
if ((err = handlesys->ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None)
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *key;
|
||||||
|
pContext->LocalToString(params[2], &key);
|
||||||
|
|
||||||
|
StringHashMap<Entry>::Result r = pTrie->map.find(key);
|
||||||
|
|
||||||
|
return r.found() ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
static cell_t RemoveFromTrie(IPluginContext *pContext, const cell_t *params)
|
static cell_t RemoveFromTrie(IPluginContext *pContext, const cell_t *params)
|
||||||
{
|
{
|
||||||
CellTrie *pTrie;
|
CellTrie *pTrie;
|
||||||
@ -710,6 +731,7 @@ REGISTER_NATIVES(trieNatives)
|
|||||||
{"StringMap.GetArray", GetTrieArray},
|
{"StringMap.GetArray", GetTrieArray},
|
||||||
{"StringMap.GetString", GetTrieString},
|
{"StringMap.GetString", GetTrieString},
|
||||||
{"StringMap.GetValue", GetTrieValue},
|
{"StringMap.GetValue", GetTrieValue},
|
||||||
|
{"StringMap.ContainsKey", ContainsKeyInTrie},
|
||||||
{"StringMap.Remove", RemoveFromTrie},
|
{"StringMap.Remove", RemoveFromTrie},
|
||||||
{"StringMap.SetArray", SetTrieArray},
|
{"StringMap.SetArray", SetTrieArray},
|
||||||
{"StringMap.SetString", SetTrieString},
|
{"StringMap.SetString", SetTrieString},
|
||||||
|
@ -114,6 +114,12 @@ methodmap StringMap < Handle
|
|||||||
// as a value or array (not a string).
|
// as a value or array (not a string).
|
||||||
public native bool GetString(const char[] key, char[] value, int max_size, int &size=0);
|
public native bool GetString(const char[] key, char[] value, int max_size, int &size=0);
|
||||||
|
|
||||||
|
// Checks whether a key is present in a Map.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @return True if the key has been found, else false.
|
||||||
|
public native bool ContainsKey(const char[] key);
|
||||||
|
|
||||||
// Removes a key entry from a Map.
|
// Removes a key entry from a Map.
|
||||||
//
|
//
|
||||||
// @param key Key string.
|
// @param key Key string.
|
||||||
|
Loading…
Reference in New Issue
Block a user