diff options
author | gumi <git@gumi.ca> | 2018-03-26 17:11:34 -0400 |
---|---|---|
committer | gumi <git@gumi.ca> | 2018-03-26 17:11:34 -0400 |
commit | 3a56da3c09845676534f460f75c8adb6c65fbb79 (patch) | |
tree | b37c703cc7dc07725235a5d916db5d83b65e8ecf /src/emap | |
parent | c3262df069c597bd3c56e167cadc077c077d0096 (diff) | |
download | evol-hercules-3a56da3c09845676534f460f75c8adb6c65fbb79.tar.gz evol-hercules-3a56da3c09845676534f460f75c8adb6c65fbb79.tar.bz2 evol-hercules-3a56da3c09845676534f460f75c8adb6c65fbb79.tar.xz evol-hercules-3a56da3c09845676534f460f75c8adb6c65fbb79.zip |
add missing hashtable iterator buildinss20180406
Diffstat (limited to 'src/emap')
-rw-r--r-- | src/emap/hashtable.c | 42 | ||||
-rw-r--r-- | src/emap/hashtable.h | 3 | ||||
-rw-r--r-- | src/emap/init.c | 3 | ||||
-rw-r--r-- | src/emap/script_buildins.c | 39 | ||||
-rw-r--r-- | src/emap/script_buildins.h | 3 |
5 files changed, 90 insertions, 0 deletions
diff --git a/src/emap/hashtable.c b/src/emap/hashtable.c index 6645a0d..1fead60 100644 --- a/src/emap/hashtable.c +++ b/src/emap/hashtable.c @@ -134,6 +134,32 @@ bool htreg_iterator_exists(int64 id) return i64db_exists(htreg->iterators, id); } +const char* htreg_iterator_firstkey(int64 id) +{ + struct DBIterator *it = i64db_get(htreg->iterators, id); + if (it) + { + union DBKey key; + it->first(it, &key); + if (dbi_exists(it)) + return key.str; + } + return NULL; +} + +const char* htreg_iterator_lastkey(int64 id) +{ + struct DBIterator *it = i64db_get(htreg->iterators, id); + if (it) + { + union DBKey key; + it->last(it, &key); + if (dbi_exists(it)) + return key.str; + } + return NULL; +} + const char* htreg_iterator_nextkey(int64 id) { struct DBIterator *it = i64db_get(htreg->iterators, id); @@ -147,6 +173,19 @@ const char* htreg_iterator_nextkey(int64 id) return NULL; } +const char* htreg_iterator_prevkey(int64 id) +{ + struct DBIterator *it = i64db_get(htreg->iterators, id); + if (it) + { + union DBKey key; + it->prev(it, &key); + if (dbi_exists(it)) + return key.str; + } + return NULL; +} + /** * Initializer. */ @@ -212,5 +251,8 @@ void htreg_defaults(void) htreg->destroy_iterator = htreg_destroy_iterator; htreg->iterator_check = htreg_iterator_check; htreg->iterator_exists = htreg_iterator_exists; + htreg->iterator_firstkey = htreg_iterator_firstkey; + htreg->iterator_lastkey = htreg_iterator_lastkey; htreg->iterator_nextkey = htreg_iterator_nextkey; + htreg->iterator_prevkey = htreg_iterator_prevkey; } diff --git a/src/emap/hashtable.h b/src/emap/hashtable.h index 44712cd..403304e 100644 --- a/src/emap/hashtable.h +++ b/src/emap/hashtable.h @@ -31,7 +31,10 @@ struct htreg_interface bool (*destroy_iterator) (int64 id); bool (*iterator_check) (int64 id); bool (*iterator_exists) (int64 id); + const char* (*iterator_firstkey) (int64 id); + const char* (*iterator_lastkey) (int64 id); const char* (*iterator_nextkey) (int64 id); + const char* (*iterator_prevkey) (int64 id); }; void htreg_defaults(void); diff --git a/src/emap/init.c b/src/emap/init.c index fefbc6c..9063735 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -183,7 +183,10 @@ HPExport void plugin_init (void) addScriptCommand("htsize", "i", htSize); addScriptCommand("htexists", "i", htExists); addScriptCommand("htiterator", "i", htIterator); + addScriptCommand("htifirstkey", "i", htiFirstKey); + addScriptCommand("htilastkey", "i", htiLastKey); addScriptCommand("htinextkey", "i", htiNextKey); + addScriptCommand("htiprevkey", "i", htiPrevKey); addScriptCommand("hticheck", "i", htiCheck); addScriptCommand("htidelete", "i", htiDelete); addScriptCommand("setfakecells", "iii??", setFakeCells); diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c index 703307a..78fb940 100644 --- a/src/emap/script_buildins.c +++ b/src/emap/script_buildins.c @@ -1991,6 +1991,32 @@ BUILDIN(htIterator) return false; \ } +BUILDIN(htiFirstKey) +{ + int64 id = script_getnum(st, 2); + checkHtIteratorExists(id); + + const char * key = htreg->iterator_firstkey(id); + if (key) + script_pushstrcopy(st, key); + else + script_pushstrcopy(st, ""); + return true; +} + +BUILDIN(htiLastKey) +{ + int64 id = script_getnum(st, 2); + checkHtIteratorExists(id); + + const char * key = htreg->iterator_lastkey(id); + if (key) + script_pushstrcopy(st, key); + else + script_pushstrcopy(st, ""); + return true; +} + BUILDIN(htiNextKey) { int64 id = script_getnum(st, 2); @@ -2004,6 +2030,19 @@ BUILDIN(htiNextKey) return true; } +BUILDIN(htiPrevKey) +{ + int64 id = script_getnum(st, 2); + checkHtIteratorExists(id); + + const char * key = htreg->iterator_prevkey(id); + if (key) + script_pushstrcopy(st, key); + else + script_pushstrcopy(st, ""); + return true; +} + BUILDIN(htiCheck) { int64 id = script_getnum(st, 2); diff --git a/src/emap/script_buildins.h b/src/emap/script_buildins.h index 2066432..a72a035 100644 --- a/src/emap/script_buildins.h +++ b/src/emap/script_buildins.h @@ -82,7 +82,10 @@ BUILDIN(htDelete); BUILDIN(htSize); BUILDIN(htExists); BUILDIN(htIterator); +BUILDIN(htiFirstKey); +BUILDIN(htiLastKey); BUILDIN(htiNextKey); +BUILDIN(htiPrevKey); BUILDIN(htiCheck); BUILDIN(htiDelete); BUILDIN(setFakeCells); |