Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KDB: In-place delete from dictionary

Tags:

dictionary

kdb

To upsert an element into the dictionary, I do

q) d[`x]:12345

This modifies existing dictionary and the operation cost is close to O(1) or O(log N) depending on the underlying implementation (hash table or tree) (I don't know in fact).

However, to remove a key I must use:

q) d:(enlist `x) _ d

Which is at least O(N) because it copies the full dictionary without deleting items in O(N) then assigns is to d in O(1) because of pointer.

This looks like delete operation discrimination! Maybe in-place delete is poorly documented but exists somewhere?

like image 480
Sanny Avatar asked Dec 04 '22 21:12

Sanny


1 Answers

Two more options include apply:

.[`d;();_;`x]

functional delete

![`d;();0b;enlist`x]

The last form is useful if you want to delete multiple keys in one go. E.g.,

![`d;();0b;`x`y]
like image 159
Alexander Belopolsky Avatar answered Dec 07 '22 23:12

Alexander Belopolsky