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?
You want a hashtable, also known as a hash map.
Isn't a map just a modified hash map?
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