But i have a little problem with this.
I am trying to do this for several Hashtables instead of only one, well the problem is that i can't pass by parameter a linked list, to every procedure
Can some one help me?
Here's the code:
Code: Select all
; Implementation of a HashTable from Java.
; A kind of indexed List
Global HashTable_Sort_Thread.b
Global HashTable_Init.b
Global AutomaticSort.b
HashTable_Init = #False
AutomaticSort = #False
HashTable_Sort_Thread = #False
AutomaticSort = #True
Structure Key_Value_Pair
Key.s
Value.s
EndStructure
;{ HashTable Declares
Declare.b HashTable_Init ( Hash.Key_Value_Pair() )
Declare.b HashTable_Stop ( Hash.Key_Value_Pair() )
Declare HashTable_Sort_Thread ( Dummy.l )
Declare PutValue ( Hash.Key_Value_Pair(), Key.s, Value.s )
Declare AddValue ( Hash.Key_Value_Pair(), Key.s, Value.s )
Declare GetValue ( Hash.Key_Value_Pair(), Key.s )
Declare DelValue ( Hash.Key_Value_Pair(), Key.s )
Declare RemoveValue ( Hash.Key_Value_Pair(), Key.s )
Declare HashSize ( Hash.Key_Value_Pair() )
Declare ContainsKey ( Hash.Key_Value_Pair(), Key.s )
;}
Procedure.b HashTable_Init( Hash.Key_Value_Pair() )
ClearList( Hash() )
ResetList( Hash() )
HashTable_Init = #True
EndProcedure
Procedure.b HashTable_Stop( Hash.Key_Value_Pair() )
ResetList( Hash() )
ClearList( Hash() )
HashTable_Init = #False
EndProcedure
Procedure HashTable_Sort_Thread( Dummy.l )
Shared HashTable_Sort_Thread.b
Shared HashTable_Init.b
Shared AutomaticSort.b
If ( HashTable_Init = #True And AutomaticSort = #True)
If ( HashTable_Sort_Thread = #True )
HashTable_Sort_Thread = #True
; Place Sort Here
HashTable_Sort_Thread = #False
EndIf
EndIf
EndProcedure
Procedure PutValue( Hash.Key_Value_Pair(), Key.s, Value.s )
AddValue( Hash(), Key.s, Value.s )
EndProcedure
Procedure AddValue( Hash.Key_Value_Pair(), Key.s, Value.s )
Shared HashTable_Sort_Thread.b
Shared HashTable_Init.b
Shared AutomaticSort.b
If ( HashTable_Init = #True )
If ( HashTable_Sort_Thread = #True )
WaitThread( #HashTable_Sort_ThreadID )
ResetList( Hash() )
AddElement( Hash() )
HashTable()\Key = Key
HashTable()\Value = Value
If ( AutomaticSort = #True )
CreateThread( @HashTable_Sort_Thread(), "" )
EndIf
EndIf
EndIf
EndProcedure
Procedure GetValue( Hash.Key_Value_Pair(), Key.s )
Protected ReturnValue.s
Shared HashTable_Sort_Thread.b
Shared HashTable_Init.b
ReturnValue = "Null"
If ( HashTable_Init = #True )
If ( HashTable_Sort_Thread = #True )
WaitThread( #HashTable_Sort_ThreadID )
ForEach ( Hash() )
If ( Hash()\Key = Key )
ReturnValue = Hash()\Value
EndIf
Next
EndIf
EndIf
ProcedureReturn ReturnValue
EndProcedure
Procedure DelValue( Hash.Key_Value_Pair(), Key.s )
Shared HashTable_Sort_Thread.b
Shared HashTable_Init.b
Shared AutomaticSort.b
If ( HashTable_Init = #True )
If ( HashTable_Sort_Thread = #True )
WaitThread( #HashTable_Sort_ThreadID )
ResetList( Hash() )
ForEach Hash()
If ( Hash()\Key = Key )
DeleteElement( Hash() )
EndIf
Next
If ( AutomaticSort = #True )
CreateThread( @HashTable_Sort_Thread(), "" )
EndIf
EndIf
EndIf
EndProcedure
Procedure RemoveValue( Hash.Key_Value_Pair(), Key.s )
DelValue( Hash(), Key )
EndProcedure
Procedure HashSize( Hash.Key_Value_Pair() )
Protected ReturnValue.l
Shared HashTable_Sort_Thread.b
Shared HashTable_Init.b
ReturnValue = 0
If ( HashTable_Init = #True )
If ( HashTable_Sort_Thread = #True )
WaitThread( #HashTable_Sort_ThreadID )
EndIf
ReturnValue = CountList( Hash() )
EndIf
ProcedureReturn ReturnValue
EndProcedure
Procedure ContainsKey( Hash.Key_Value_Pair(), Key.s )
Protected ReturnValue.l
Shared HashTable_Sort_Thread.b
Shared HashTable_Init.b
ReturnValue = #False
If ( HashTable_Init = #True )
If ( HashTable_Sort_Thread = #True )
WaitThread( #HashTable_Sort_ThreadID )
EndIf
ForEach ( Hash() )
If ( Hash()\Key = Key )
ReturnValue = #True
EndIf
Next
EndIf
ProcedureReturn ReturnValue
EndProcedure
Thanks in advance.