• Welcome to Valhalla Legends Archive.
 

Best storage method

Started by warz, March 18, 2006, 10:33 AM

Previous topic - Next topic

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?

Banana fanna fo fanna

You want a hashtable, also known as a hash map.

warz

Isn't a map just a modified hash map?

Joe[x86]

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
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

SecretShop