Re: Design of string storage
- From: Joerg <bregg@xxxxxx>
- Date: Sat, 17 Dec 2005 15:41:50 +0100
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.
.
- References:
- Design of string storage
- From: Joerg
- Re: Design of string storage
- From: Chuck F.
- Re: Design of string storage
- From: Joerg
- Re: Design of string storage
- From: Chuck F.
- Design of string storage
- Prev by Date: Re: Creating a Windows Menu
- Next by Date: Re: Design of string storage
- Previous by thread: Re: Design of string storage
- Next by thread: Re: Design of string storage
- Index(es):
Relevant Pages
|