Re: Design of string storage





Chuck F. wrote:
> Obviously you didn't look at my recommendations

I did. And what I found was an implementation of a hash map.
But maybe I didn't understand the text in the usage file.

If I followed the instructions there I would define a structure that
contains my string and maybe a kind of reference counting.

struct item
{
char* string;
int count;
};

Then I would define some copy, allocation and free methods for this
structure.

And then I would use the map. I would search for an item and if not
found I would insert it into the map:


item* p = hshfind(table, &myItem);
if (!p) p = hshinsert(table, &myItem);

The return value of this operation I would store in my object and
furthermore I would increase the ref count.

obj.setName(p);
++(p->count);

So far so good.

If I destroy my object I would decrease the ref count and maybe remove the
item from the map;

if (!(--(name->count)))
{
hshdelete(table, name);
myundupe(name);
}

Ok until now, a more or less comfortable/customizable hash map.

But now the real problem: If I want the objects to be contignous in memory
now is the time to move the other items in the map to fill the gap. (Maybe
implemented in myundupe())
But how do I do that? I don't know where the objects are located that hold
a pointer to one of the items inside the map that will be moved.

>, and equally
> obviously you failed to provide any context.

Any information I used to produce the code above was mentioned in the
original posting. If you need additional information feel free to ask. I
provided any information that I found useful.

Joerg.

.



Relevant Pages

  • Re: Is STL::map Find operation the optimised ?
    ... If your map contains keys that are long and highly differentiated by ... can actually end up being faster than a hash map, ... characters, millions of records), I would not expect hash_map to be slower. ... both of them with your real data. ...
    (microsoft.public.vc.stl)
  • Data structure recommendation?
    ... hash map. ... I want to map a RANGE of floats to an object. ... getshould return the object with the "newest" timestamp ...
    (comp.lang.python)
  • Re: Weak/Soft references?
    ... map, which you keep as ... indefinitely even if there is no other references to a list element. ... hinder collection. ... stops using the object, it will be removed from the hash map as well, so ...
    (comp.lang.java.programmer)
  • Re: CMap and struct
    ... As to HashKey(), you probably don't really need a hashed map, in which case you could use std::map from the standard library (std::map is a tree-based map, not a hash map). ...
    (microsoft.public.vc.mfc)
  • Re: Kirsten Seavers Vinland Map book- first thoughts
    ... Anyhow what I have here and now is a ref to Populär Arkeologi nr 2 2004. ... "Matthew Harley" skrev i meddelandet ... > Inger E Johansson wrote: ... >> map. ...
    (sci.archaeology)