logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Hashmap plugin - do you use/plan to use it under nwnx4?

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Development
View previous topic :: View next topic  
Author Message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Fri Mar 09, 2007 18:08    Post subject: Hashmap plugin - do you use/plan to use it under nwnx4? Reply with quote

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
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Sat Mar 10, 2007 1:00    Post subject: Re: Hashmap plugin - do you use/plan to use it under nwnx4? Reply with quote

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
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Sat Mar 10, 2007 1:59    Post subject: Reply with quote

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 Wink
_________________
Khalidine, a NWN2 persistent world

Looking for volunteers.
Back to top
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Tue Mar 13, 2007 0:47    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Development All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group