| Subject |
ot4xb - Build: 1_5_2_54 |
| From |
Pablo Botella |
| Date |
Sat, 30 Aug 2008 23:06:44 +0200 |
| Newsgroups |
ot4xb.snapshots |
| Attachment(s) |
_ot4xb_.zip, HashTableNotes.txt, TestHash.zip |
ot4xb - Build: 1_5_2_54
|
Hash Table Functions:
_HDICT_NEW() -> pHt - Create a new hash table and return the handle
_HDICT_KEY_COMPARE( key1 , key2 ) -> lEqual - Compare 2 keys (num,char or date) and return .T. if are equivalents
_HDICT_DESTROY(pHt) - Release memory used to store the hash table.
_HDICT_SETPROP(pHt, key , val ) - Add new entry to the hash table and discard previous if any.
_HDICT_GETPROP(pHt,key ) - Retrieve a value or NIL if entry not exist.
_HDICT_REMOVEPROP(pHt,key) - Remove a entry if exist
_HDICT_REMOVEALL(pHt) - Remove all entries
_HDICT_COUNT(pHt) - Count existing entries in the hash table
// ---------------------------------------------------------------------------
_HDICT_ITERATE_STEP(pHt,@pIterator,@item,@key) - Return 1 item at time from the hash table storage
pIterator must be passed by reference and must be NIL the first time the function is called
item and key params will receive the key and item values for each iteration
_HDICT_ITERATE_STEP() will return .T. while not reach the end of storage
See the following sample:
i := k := v := NIL
while _HDICT_ITERATE_STEP( pHt, @i, @v , @k)
? k ," -> " , v
end
NOTES:
- pIterator MUST NOT be changed by the application
- Items inside the hash storage are sorted in random order acording with the hash algoritm
so iterate the entire hash table will warrat all items are retrieved but not the order
in wich you retrieve the items
- Remove items inside the iteration can result into a memory exception
- Add items withing the iteration can produce dupe evaluations
// ---------------------------------------------------------------------------
_HDICT_ITERATE_CB( pHt , codeblock , @cargo ) - Evaluate a codeblock across all items
The codeblock will receive 4 params nItemPosition , cKey , xValue and the provided cargo
The codeblock must return .T. to continue or .F. to stop
See the following sample:
aItems := Array( _HDICT_COUNT( pDict ) , 2 )
cbk := {|pos,key,val,cargo| cargo[pos][1] := key ,cargo[pos][2] := val, .T. }
_HDICT_ITERATE_CB( pDict, cbk , @aItems )
NOTES:
- Items inside the hash storage are sorted in random order acording with the hash algoritm
so iterate the entire hash table will warrat all items are retrieved but not the order
in wich you retrieve the items
- Remove items inside the iteration can result into a memory exception
- Add items withing the iteration can produce dupe evaluations
// ---------------------------------------------------------------------------
_HDICT_* functions and multi-thread
=========================
_HDICT_* functions and THDict class don't provide builtin multithread serialization
But your classes can provide the required multithread suppor in a easy manner
just using SYNC methods
Example:
CLASS Dictionary
EXPORTED:
VAR ht
INLINE METHOD init() ; ::ht := _HDICT_NEW() ; return Self
INLINE SYNC METHOD Destroy() ; _HDICT_DESTROY(::ht) ; ::ht := NIL ; return Self
INLINE SYNC METHOD Put(key,val); return _HDICT_SETPROP(::ht,key,val)
INLINE SYNC METHOD Get(key) ; return _HDICT_GETPROP(::ht,key)
INLINE SYNC METHOD Del(key) ; return _HDICT_REMOVEPROP(::ht,key)
INLINE SYNC METHOD Zap() ; return _HDICT_REMOVEALL(::ht)
ENDCLASS
// ---------------------------------------------------------------------------
|
|