O(1) "popAny" for associative array?

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 11 11:09:40 PST 2014


H. S. Teoh:

> On the other hand, AA.byKey() will return a *lazy* sequence of 
> keys
> (i.e., it won't actually walk the AA unless you want it to), so 
> doing
> this ought to be O(1):
>
> 	auto mykey = myarray.byKey().front;
> 	myarray.remove(mykey);

In general the associative array table can have many empty slots, 
so byKey.front is not always O(1). But AAs were recently 
improved, now byKey.front is much faster.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list