3

Is there memory AND speed efficient way to store unique key:value pairs dynamically in hash map? Keys are guaranteed to be unique but the amount of them is changing frequently. Insertion and deletion has to be fast.

What I've done is octree (not linear/full) containing signed distance field. Octree is updated often. What I'd like to do is try to make it pointerless to save some space.

pks
  • 51
  • 6

1 Answers1

0

I'm not sure about using a hashmap, as dynamic structures tend to either lose the O(1) lookup that a hashmap benefits from or allocate extra memory and require reallocation when that memory is used up. You can, however, create an octree where each node only has one pointer.

for example, in c++ one might do something like:

struct node{
    node* next;//pointer to children
    unsigned byte shape;//8bit flag indicating which children actually exist

    node():next(0),shape(0){}
};
void initChildren(node& parent,unsigned byte state=0){
    if(!parent.next){//only allocate the array if it has not yet been allocated
        parent.next=new node[8];//the children are allocated in consecutive memory
    }
    shape=state;
}

Deleting a child node only requires setting a bit in the shape field to 0. I hope this helps you, even if you did ask a while ago.