[Geany-Devel] On document pointer recycling

Matthew Brush mbrush at xxxxx
Fri Oct 25 04:30:08 UTC 2013


On 13-10-24 08:34 PM, Lex Trotman wrote:
> [...]
>
> We could use GHashTable as a Set to contain the documents internally
>> afterwards. It doesn't make much sense to have a particular document
>> instantiated more than once anyway and the only order we care about for
>> documents here is maybe the order/time they were opened, which is better
>> solved with a "open timestamp" or something, IMO.
>>
>
> The current index does not depend on opening order since it recycles the
> document structs, so there can be no dependency on the current order that
> makes sense.
>

I don't follow. I didn't mean to imply the current way cares about the 
index order, I'm just saying since we don't care, a good data structure 
for that is a "set", which in GLib is done with GHashTable.

> What would you use as the key to the hash/set, and why? A simple list or
> array is all thats needed to hold pointers to open documents and iterate
> them.
>

I'd use it, as mentioned, as a "set" data structure (unique unordered 
collection, like std::unordered_set in C++ or set() in Python) where the 
key is the document and value is the document (GHashTable has special 
case for use as a "set" like this to avoid extra memory allocation 
IIRC). It's definitively not complicated and the GHashTable API is quite 
nice, IMO.

Cheers,
Matthew Brush
















More information about the Devel mailing list