Add new trie native: ContainsKey() (#1390)

This commit is contained in:
Einyux 2020-12-01 05:51:47 +01:00 committed by GitHub
parent 0caa349f6a
commit a191a907e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -350,6 +350,27 @@ static cell_t SetTrieString(IPluginContext *pContext, const cell_t *params)
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)
{
CellTrie *pTrie;
@ -710,6 +731,7 @@ REGISTER_NATIVES(trieNatives)
{"StringMap.GetArray", GetTrieArray},
{"StringMap.GetString", GetTrieString},
{"StringMap.GetValue", GetTrieValue},
{"StringMap.ContainsKey", ContainsKeyInTrie},
{"StringMap.Remove", RemoveFromTrie},
{"StringMap.SetArray", SetTrieArray},
{"StringMap.SetString", SetTrieString},

View File

@ -114,6 +114,12 @@ methodmap StringMap < Handle
// as a value or array (not a string).
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.
//
// @param key Key string.