Created
August 8, 2014 10:50
-
-
Save seanbamforth/3bd0d85ff41a8736d72c to your computer and use it in GitHub Desktop.
cDictionary - using Native Arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Struct tKeyValue | |
String sKey | |
String sValue | |
End_Struct | |
Class cDictionary is a cObject | |
Procedure construct_object | |
Forward Send Construct_Object | |
Property tKeyValue[] pDictionary | |
End_Procedure | |
Function CompareKey tKeyValue keyValue1 tKeyValue keyValue2 Returns Integer | |
If (keyValue1.sKey > keyValue2.sKey) Function_Return (GT) | |
If (keyValue1.sKey < keyValue2.sKey) Function_Return (LT) | |
Function_Return (EQ) | |
End_Function | |
Procedure Set key String sKey String sValue | |
tKeyValue[] Dictionary | |
tKeyValue KeyValueItem | |
Integer iSearchIndex | |
Integer iMax | |
Move (Uppercase(sKey)) to sKey | |
Get pDictionary to Dictionary | |
Move sKey to KeyValueItem.sKey | |
Move sValue to KeyValueItem.sValue | |
Move (SearchArray(KeyValueItem, Dictionary, Self, (RefFunc(CompareKey)))) to iSearchIndex | |
Move (SizeOfArray(Dictionary)) to iMax | |
If (iSearchIndex = -1) Move KeyValueItem to Dictionary[iMax] | |
Else Move KeyValueItem to Dictionary[iSearchIndex] | |
Set pDictionary to Dictionary | |
End_Procedure | |
Procedure delete_data | |
tKeyValue[] Dictionary | |
Set pDictionary to Dictionary | |
End_Procedure | |
Function key String sKey Returns String | |
Integer iSearchIndex | |
tKeyValue[] Dictionary | |
tKeyValue KeyValueItem | |
Move (Uppercase(sKey)) to sKey | |
Move sKey to KeyValueItem.sKey | |
Get pDictionary to Dictionary | |
Move (SearchArray(KeyValueItem, Dictionary, Self, (RefFunc(CompareKey)))) to iSearchIndex | |
If (iSearchIndex = -1) Function_Return (False) | |
Function_Return Dictionary[iSearchIndex].sValue | |
End_Function | |
End_Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment