Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: warz on March 18, 2006, 10:33 AM

Title: Best storage method
Post by: warz on March 18, 2006, 10:33 AM
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?
Title: Re: Best storage method
Post by: Banana fanna fo fanna on March 21, 2006, 09:41 PM
You want a hashtable, also known as a hash map.
Title: Re: Best storage method
Post by: warz on March 21, 2006, 11:08 PM
Isn't a map just a modified hash map?
Title: Re: Best storage method
Post by: Joe[x86] on March 21, 2006, 11:09 PM
I suck, but I'd probably do something like.. (VB)

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
Title: Re: Best storage method
Post by: SecretShop on March 29, 2006, 02:49 PM
Quote from: warz on March 21, 2006, 11:08 PM
Isn't a map just a modified hash map?
no