summaryrefslogtreecommitdiff
path: root/library/lua/utils.lua
diff options
context:
space:
mode:
Diffstat (limited to 'library/lua/utils.lua')
-rw-r--r--library/lua/utils.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/library/lua/utils.lua b/library/lua/utils.lua
index 9fa473ed..b46363cd 100644
--- a/library/lua/utils.lua
+++ b/library/lua/utils.lua
@@ -361,6 +361,27 @@ function insert_or_update(vector,item,field,cmp)
return added,cur,pos
end
+-- Binary search and erase
+function erase_sorted_key(vector,key,field,cmp)
+ local cur,found,pos = binsearch(vector,key,field,cmp)
+ if found then
+ if df.isvalid(vector) then
+ vector:erase(pos)
+ else
+ table.remove(vector, pos)
+ end
+ end
+ return found,cur,pos
+end
+
+function erase_sorted(vector,item,field,cmp)
+ local key = item
+ if field and item then
+ key = item[field]
+ end
+ return erase_sorted_key(vector,key,field,cmp)
+end
+
-- Calls a method with a string temporary
function call_with_string(obj,methodname,...)
return dfhack.with_temp_object(