Ok, i figured id share this type/class with the community..
already sent a copy to noel, but no doubt others would like
a basic hashtable system too..
this is my first bmax class - perhaps not great, but it does
the job...anyway enjoy ;)
feel free to credit me if you use it :]
already sent a copy to noel, but no doubt others would like
a basic hashtable system too..
this is my first bmax class - perhaps not great, but it does
the job...anyway enjoy ;)
feel free to credit me if you use it :]
''InsertEntry(name:string,o:object) - add an object to the table, the name is used to '' to generate an index 0-255, selecting the list. '' ''RemoveEntry(name:string) - if you need to remove an object. '' ''GetEntry(name:string) - grab an entry, you must cast is back to its original type, '' myobject=myType(GetEntry(name:string)) '' '' ''Flush() - removes all objects from the hash table '' '' ''all entries should have unique names - you should first getEntry(), if this returns ''null - its safe to insert the new object, if it returns a valid object, you may want ''to return this object back to the user... ''''''''''''''''''''''''''' '' ''HASHTABLE OBJECT '' ''- M.Laurenson/Defoc8 2006 '''''''''''''''''''''''''''' Type gHashTable Field table:TList[] Method New() table=table[..256] For Local n:Int=0 To 255 table[n]=CreateList() Next EndMethod Method genIndex(name$) Local val:Int=0 For Local n:Int=0 To name.length-1 val=val+(name[n]^2) Next val=(val&255) Return val EndMethod Method insertEntry(name:String,obj:Object) Local index:Int=genIndex(name$) Local entry:gHashEntry=New gHashEntry entry.name=name entry.obj=obj entry.link=ListAddLast(table[index],entry) EndMethod Method removeEntry(name:String) Local index:Int=genIndex(name) For Local entry:gHashEntry=EachIn table[index] If(entry.name=name) RemoveLink(entry.link) Return EndIf Next EndMethod Method getEntry:Object(name:String) Local index:Int=genIndex(name) For Local entry:gHashEntry=EachIn table[index] If(entry.name=name) Return(entry.obj) EndIf Next Return Null EndMethod Method flush() For Local n:Int=0 To 255 ClearList(table[n]) Next EndMethod Method getEntryCount(index:Int) Return CountList(table[index]) EndMethod EndType Type gHashEntry Field name:String Field obj:Object Field link:TLink EndType