Removing any item from an associative array

I would like to remove element (y) from the associative array and process it. I am currently using RedBlackTree with .removeAny() , but I do not need the data in any order. I could use .byKey() in AA, but it always creates an array with all the keys. I only need one at a time and will probably change AA when processing every other element. Is there another smart way to get exactly one key without (inside) going through the entire data structure?

+4
source share
1 answer

There is a workaround that works, and also uses .byKeys() :

 auto anyKey(K, V)(inout ref V[K] aa) { foreach (K k, ref inout(V) v; aa) return k; assert(0, "Associative array hasn't any keys."); } 

For my needs .byKeys().front seems fast enough. Not sure if the workaround is actually faster.

+2
source

All Articles