Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Most performant way to store hashtables

Status
Not open for further replies.

tektipster79

Programmer
Oct 1, 2007
34
US
I need to store hashtables that hold index information into collections of items stored in classes representing an XML document (generated by a tool similar to xsd.exe). For instance, suppose I have the following XML structure (please excuse my lame example):

Code:
<Dresser>
  <Drawer>
    <SockOrganizer>
      <Compartment>
        <sock color=red></sock>
        <sock color=blue></sock>
      </Compartment>
      <Compartment>
        <sock color=red></sock>
        <sock color=blue></sock>
        <sock color=white></sock>
        <sock color=black></sock>
      </Compartment>
    </SockOrganizer>
  </Drawer>
  <Drawer>
    <SockOrganizer>
        <sock color=red></sock>
    </SockOrganizer>
    <SockOrganizer>
        <sock color=red></sock>
        <sock color=purple></sock>
    </SockOrganizer>
  </Drawer>
</Dresser>

So in order to navigate to a sock collection, I need the index of the drawer and the sock organizer.

Would it be better for me to create some sort of custom collection that has a drawer and sock organizer property and then a hashtable holding the index of the socks, or would it be ok (performant) to use a multi dimensional array?

 
performant - Performant is not a word. :)

A generic Dictionary<> with a List<> of a custom class would work well for you. That would make it easy to work with and quick to search for the items you need.

 
touché on performant :)

I'm not sure how I understand how I can represent the relationships with a dictionary. Right now my custom classes are generic lists, so that part is good. I basically just need to be able to get the index of the drawer, and the index of the compartment. Then the hashtable will store all of the socks, with another identifier (that is not the equivalent of the index, it's for something else). So for a dictionary, I was thinking it wouldn't work because I can only represent at most a relationship between 2 items.

Right now, I have a hashtable that holds all of the (DrawerName, index). Then a generic list of hashtables, where the index of the hashtable in the collection is equal to the index of the DrawerName, and the corresponding hashtable holds (ContainerName, index). Just not sure what the best option is now. I'm not the best with collections, so what I've done so far might be a bad idea, but it's what I've come up with so far :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top