View previous topic :: View next topic |
Author |
Message |
Grinning Fool
Joined: 12 Feb 2005 Posts: 264
|
Posted: Fri Mar 09, 2007 18:08 Post subject: Hashmap plugin - do you use/plan to use it under nwnx4? |
|
|
The reason I ask is that a) I'm in the midst of porting it over and b) I was looking at some potential interface changes, and was wondering if they would affect you.
Basically, I would like to split out the hashmap functions from the array functions. Since we're switching over to the wxWidgets implementation of hashmap, we don't have direct array-like access to the elements stored in the map. This is unlike under NWNX2, where we did have direct access ( though order of storage was not guaranteed)
That leaves a two options to implement this:
1. I could store two copies of data pointers -- one in indexed/array form, and one in hashmap form. By doing this, I would be able to offer the equivalent functionality to what we have today. (Note that I don't mean two copies of the data -- each entry into the hashmap is a pointer to the actual data. I would be storing that pointer in two places.)
2. Split out the array functions and hashmap functions. This would be both programatically 'cleaner' and also more efficient as it eliminates double-allocations for pointer storage.
If there are a large number of people who are depending on the existing nterface in porting over to NWN2, I'll choose option 1 above. But if not, option 2 would be a more efficient way of coding.
Please reply below if you're planning to use the plugin under nwnx4, and if you have a preference as to which implementation I go with. _________________ Khalidine, a NWN2 persistent world
Looking for volunteers. |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Sat Mar 10, 2007 1:00 Post subject: Re: Hashmap plugin - do you use/plan to use it under nwnx4? |
|
|
Grinning Fool wrote: |
Basically, I would like to split out the hashmap functions from the array functions. Since we're switching over to the wxWidgets implementation of hashmap, we don't have direct array-like access to the elements stored in the map. This is unlike under NWNX2, where we did have direct access ( though order of storage was not guaranteed) |
Only sort-of true.
wxWidgets provides a (forwards only) iterator over the HashMap.
This means you'd need to contain the iterator in a control-loop to find the n'th element.
Code: |
hash[key] = value;
...
// iterate over all the elements in the class
MyHash::iterator it;
for( it = hash.begin(); it != hash.end(); ++it )
{
wxString key = it->first, value = it->second;
// do something useful with key and value
}
|
Insert a 'counter' into the loop and you can index each element.
I wouldn't track the index as it will get corrupted with insert() and erase() operations as order is not guaranteed.
To get PREV simply replace hash.end() with the current iterator. (if still valid)
But to answer the question - I'd prefer move forward and make better use of the wxClasses that are available.
Cheers
Gryphyn |
|
Back to top |
|
|
Grinning Fool
Joined: 12 Feb 2005 Posts: 264
|
Posted: Sat Mar 10, 2007 1:59 Post subject: |
|
|
I didn't mention that option because iterating through the hashmap n times whenever someone requested element n is even less efficient than the first option I mentioned above _________________ Khalidine, a NWN2 persistent world
Looking for volunteers. |
|
Back to top |
|
|
Grinning Fool
Joined: 12 Feb 2005 Posts: 264
|
Posted: Tue Mar 13, 2007 0:47 Post subject: |
|
|
Alright, given the overwhelming response from people who are using the plugin, I will be proceeding with plans to change the interface. I'll be providing a set of array functions separate from the hash functions. This should be even better after the native int data passing becomes available in 1.05.
[/code] _________________ Khalidine, a NWN2 persistent world
Looking for volunteers. |
|
Back to top |
|
|
|