Valhalla Legends Forums Archive | C/C++ Programming | Best storage method

AuthorMessageTime
warz
I'm working on a certain database management class, and am trying to figure out what the best method of storing my database keys would be.

My database will be storing names, for example. Each name will have two other values associated with it. I want to store this information in a struct, and just create an array of structs, or something.

I was looking into certain methods, thinking there had to be something cleaner. I found the map class. I was wondering though, what are some other quality methods of containing these values?
March 18, 2006, 4:33 PM
St0rm.iD
You want a hashtable, also known as a hash map.
March 22, 2006, 3:41 AM
warz
Isn't a map just a modified hash map?
March 22, 2006, 5:08 AM
JoeTheOdd
I suck, but I'd probably do something like.. (VB)

[code]Dim Field1() as [Type]
Dim Field2() as [Type]
Dim Field3() as [Type]

' Pass ID and blank fields, returns variables in ByVal fields
Public Sub ReadRecord(ByRef ID as Integer, ByVal Var1 as [Type], ByVal Var2 as [Type], ByVal Var3 as [Type])
    Var1 = Field1(ID)
    Var2 = Field2(ID)
    Var3 = Field3(ID)
End Sub

' Returns position in array
Public Function AddRecord(ByRef Var1 as [Type], ByRef Var2 as [Type], ByRed Var3 as [Type]) as Integer
    Redim Preserve Field1(LBound(Field1) to UBound(Field1) + 1)
    Redim Preserve Field2(LBound(Field2) to UBound(Field2) + 1)
    Redim Preserve Field3(LBound(Field3) to UBound(Field3) + 1)
    Field1(UBound(Field1) = Var1
    Field2(UBound(Field2) = Var2
    Field3(UBound(Field3) = Var3
    AddRecord = UBound(Field1)
End Function

Public Function NumberOfRecords() As Integer
    NumberOfRecords = UBound(Field1) - LBound(Field1)
End Function[/code]
March 22, 2006, 5:09 AM
SecretShop
[quote author=warz link=topic=14536.msg148844#msg148844 date=1143004102]
Isn't a map just a modified hash map?
[/quote]
no
March 29, 2006, 8:49 PM

Search