|
@@ -186,6 +186,9 @@ End Type
|
|
|
|
|
|
'***** PUBLIC *****
|
|
'***** PUBLIC *****
|
|
|
|
|
|
|
|
+Rem
|
|
|
|
+bbdoc: An key/value (Object/Object) map backed by a Red/Black tree.
|
|
|
|
+End Rem
|
|
Type TMap
|
|
Type TMap
|
|
|
|
|
|
?Not Threaded
|
|
?Not Threaded
|
|
@@ -193,6 +196,10 @@ Type TMap
|
|
Clear
|
|
Clear
|
|
End Method
|
|
End Method
|
|
?
|
|
?
|
|
|
|
+ Rem
|
|
|
|
+ bbdoc: Clears the map.
|
|
|
|
+ about: Removes all keys and values.
|
|
|
|
+ End Rem
|
|
Method Clear()
|
|
Method Clear()
|
|
If _root=nil Return
|
|
If _root=nil Return
|
|
_root.Clear
|
|
_root.Clear
|
|
@@ -202,10 +209,18 @@ Type TMap
|
|
?
|
|
?
|
|
End Method
|
|
End Method
|
|
|
|
|
|
|
|
+ Rem
|
|
|
|
+ bbdoc: Checks if the map is empty.
|
|
|
|
+ about: #True if @map is empty, otherwise #False.
|
|
|
|
+ End Rem
|
|
Method IsEmpty()
|
|
Method IsEmpty()
|
|
Return _root=nil
|
|
Return _root=nil
|
|
End Method
|
|
End Method
|
|
|
|
|
|
|
|
+ Rem
|
|
|
|
+ bbdoc: Inserts a key/value pair into the map.
|
|
|
|
+ about: If the map already contains @key, its value is overwritten with @value.
|
|
|
|
+ End Rem
|
|
Method Insert( key:Object,value:Object )
|
|
Method Insert( key:Object,value:Object )
|
|
|
|
|
|
Assert key Else "Can't insert Null key into map"
|
|
Assert key Else "Can't insert Null key into map"
|
|
@@ -248,15 +263,28 @@ Type TMap
|
|
_InsertFixup node
|
|
_InsertFixup node
|
|
End Method
|
|
End Method
|
|
|
|
|
|
|
|
+ Rem
|
|
|
|
+ bbdoc: Checks if the map contains @key.
|
|
|
|
+ returns: #True if the map contains @key.
|
|
|
|
+ End Rem
|
|
Method Contains( key:Object )
|
|
Method Contains( key:Object )
|
|
Return _FindNode( key )<>nil
|
|
Return _FindNode( key )<>nil
|
|
End Method
|
|
End Method
|
|
|
|
|
|
|
|
+ Rem
|
|
|
|
+ bbdoc: Finds a value given a @key.
|
|
|
|
+ returns: The value associated with @key.
|
|
|
|
+ about: If the map does not contain @key, a #Null object is returned.
|
|
|
|
+ End Rem
|
|
Method ValueForKey:Object( key:Object )
|
|
Method ValueForKey:Object( key:Object )
|
|
Local node:TNode=_FindNode( key )
|
|
Local node:TNode=_FindNode( key )
|
|
If node<>nil Return node._value
|
|
If node<>nil Return node._value
|
|
End Method
|
|
End Method
|
|
|
|
|
|
|
|
+ Rem
|
|
|
|
+ bbdoc: Remove a key/value pair from the map.
|
|
|
|
+ returns: #True if @key was removed, or #False otherwise.
|
|
|
|
+ End Rem
|
|
Method Remove( key:Object )
|
|
Method Remove( key:Object )
|
|
Local node:TNode=_FindNode( key )
|
|
Local node:TNode=_FindNode( key )
|
|
If node=nil Return 0
|
|
If node=nil Return 0
|
|
@@ -267,6 +295,11 @@ Type TMap
|
|
Return 1
|
|
Return 1
|
|
End Method
|
|
End Method
|
|
|
|
|
|
|
|
+ Rem
|
|
|
|
+ bbdoc: Gets the map keys.
|
|
|
|
+ returns: An enumeration object
|
|
|
|
+ about: The object returned by #Keys can be used with #EachIn to iterate through the keys in the map.
|
|
|
|
+ End Rem
|
|
Method Keys:TMapEnumerator()
|
|
Method Keys:TMapEnumerator()
|
|
Local nodeenum:TNodeEnumerator=New TKeyEnumerator
|
|
Local nodeenum:TNodeEnumerator=New TKeyEnumerator
|
|
nodeenum._node=_FirstNode()
|
|
nodeenum._node=_FirstNode()
|
|
@@ -279,6 +312,11 @@ Type TMap
|
|
Return mapenum
|
|
Return mapenum
|
|
End Method
|
|
End Method
|
|
|
|
|
|
|
|
+ Rem
|
|
|
|
+ bbdoc: Get the map values.
|
|
|
|
+ returns: An enumeration object.
|
|
|
|
+ about: The object returned by #Values can be used with #EachIn to iterate through the values in the map.
|
|
|
|
+ End Rem
|
|
Method Values:TMapEnumerator()
|
|
Method Values:TMapEnumerator()
|
|
Local nodeenum:TNodeEnumerator=New TValueEnumerator
|
|
Local nodeenum:TNodeEnumerator=New TValueEnumerator
|
|
nodeenum._node=_FirstNode()
|
|
nodeenum._node=_FirstNode()
|
|
@@ -291,15 +329,22 @@ Type TMap
|
|
Return mapenum
|
|
Return mapenum
|
|
End Method
|
|
End Method
|
|
|
|
|
|
|
|
+ Rem
|
|
|
|
+ bbdoc: Returns a copy the contents of this map.
|
|
|
|
+ End Rem
|
|
Method Copy:TMap()
|
|
Method Copy:TMap()
|
|
Local map:TMap=New TMap
|
|
Local map:TMap=New TMap
|
|
'avoid copying an empty map (_root = nil there), else it borks "eachin"
|
|
'avoid copying an empty map (_root = nil there), else it borks "eachin"
|
|
- if _root <> nil
|
|
|
|
|
|
+ If _root <> nil
|
|
map._root=_root.Copy( nil )
|
|
map._root=_root.Copy( nil )
|
|
- endif
|
|
|
|
|
|
+ EndIf
|
|
Return map
|
|
Return map
|
|
End Method
|
|
End Method
|
|
|
|
|
|
|
|
+ Rem
|
|
|
|
+ bbdoc: Returns a node enumeration object.
|
|
|
|
+ about: The object returned by #ObjectEnumerator can be used with #EachIn to iterate through the nodes in the map.
|
|
|
|
+ End Rem
|
|
Method ObjectEnumerator:TNodeEnumerator()
|
|
Method ObjectEnumerator:TNodeEnumerator()
|
|
Local nodeenum:TNodeEnumerator=New TNodeEnumerator
|
|
Local nodeenum:TNodeEnumerator=New TNodeEnumerator
|
|
nodeenum._node=_FirstNode()
|
|
nodeenum._node=_FirstNode()
|
|
@@ -530,7 +575,7 @@ Type TMap
|
|
End Type
|
|
End Type
|
|
|
|
|
|
Rem
|
|
Rem
|
|
-bbdoc: Create a map
|
|
|
|
|
|
+bbdoc: Creates a map
|
|
returns: A new map object
|
|
returns: A new map object
|
|
End Rem
|
|
End Rem
|
|
Function CreateMap:TMap()
|
|
Function CreateMap:TMap()
|
|
@@ -538,7 +583,7 @@ Function CreateMap:TMap()
|
|
End Function
|
|
End Function
|
|
|
|
|
|
Rem
|
|
Rem
|
|
-bbdoc: Clear a map
|
|
|
|
|
|
+bbdoc: Clears a map
|
|
about:
|
|
about:
|
|
#ClearMap removes all keys and values from @map
|
|
#ClearMap removes all keys and values from @map
|
|
End Rem
|
|
End Rem
|
|
@@ -547,7 +592,7 @@ Function ClearMap( map:TMap )
|
|
End Function
|
|
End Function
|
|
|
|
|
|
Rem
|
|
Rem
|
|
-bbdoc: Check if a map is empty
|
|
|
|
|
|
+bbdoc: Checks if a map is empty
|
|
returns: True if @map is empty, otherwise false
|
|
returns: True if @map is empty, otherwise false
|
|
End Rem
|
|
End Rem
|
|
Function MapIsEmpty( map:TMap )
|
|
Function MapIsEmpty( map:TMap )
|
|
@@ -555,7 +600,7 @@ Function MapIsEmpty( map:TMap )
|
|
End Function
|
|
End Function
|
|
|
|
|
|
Rem
|
|
Rem
|
|
-bbdoc: Insert a key/value pair into a map
|
|
|
|
|
|
+bbdoc: Inserts a key/value pair into a map
|
|
about:
|
|
about:
|
|
If @map already contained @key, it's value is overwritten with @value.
|
|
If @map already contained @key, it's value is overwritten with @value.
|
|
End Rem
|
|
End Rem
|
|
@@ -564,7 +609,7 @@ Function MapInsert( map:TMap,key:Object,value:Object )
|
|
End Function
|
|
End Function
|
|
|
|
|
|
Rem
|
|
Rem
|
|
-bbdoc: Find a value given a key
|
|
|
|
|
|
+bbdoc: Finds a value given a key
|
|
returns: The value associated with @key
|
|
returns: The value associated with @key
|
|
about:
|
|
about:
|
|
If @map does not contain @key, a #Null object is returned.
|
|
If @map does not contain @key, a #Null object is returned.
|
|
@@ -574,7 +619,7 @@ Function MapValueForKey:Object( map:TMap,key:Object )
|
|
End Function
|
|
End Function
|
|
|
|
|
|
Rem
|
|
Rem
|
|
-bbdoc: Check if a map contains a key
|
|
|
|
|
|
+bbdoc: Checks if a map contains a key
|
|
returns: True if @map contains @key
|
|
returns: True if @map contains @key
|
|
End Rem
|
|
End Rem
|
|
Function MapContains( map:TMap,key:Object )
|
|
Function MapContains( map:TMap,key:Object )
|
|
@@ -582,14 +627,14 @@ Function MapContains( map:TMap,key:Object )
|
|
End Function
|
|
End Function
|
|
|
|
|
|
Rem
|
|
Rem
|
|
-bbdoc: Remove a key/value pair from a map
|
|
|
|
|
|
+bbdoc: Removes a key/value pair from a map
|
|
End Rem
|
|
End Rem
|
|
Function MapRemove( map:TMap,key:Object )
|
|
Function MapRemove( map:TMap,key:Object )
|
|
map.Remove key
|
|
map.Remove key
|
|
End Function
|
|
End Function
|
|
|
|
|
|
Rem
|
|
Rem
|
|
-bbdoc: Get map keys
|
|
|
|
|
|
+bbdoc: Gets map keys
|
|
returns: An iterator object
|
|
returns: An iterator object
|
|
about:
|
|
about:
|
|
The object returned by #MapKeys can be used with #EachIn to iterate through
|
|
The object returned by #MapKeys can be used with #EachIn to iterate through
|
|
@@ -600,7 +645,7 @@ Function MapKeys:TMapEnumerator( map:TMap )
|
|
End Function
|
|
End Function
|
|
|
|
|
|
Rem
|
|
Rem
|
|
-bbdoc: Get map values
|
|
|
|
|
|
+bbdoc: Gets map values
|
|
returns: An iterator object
|
|
returns: An iterator object
|
|
about:
|
|
about:
|
|
The object returned by #MapValues can be used with #EachIn to iterate through
|
|
The object returned by #MapValues can be used with #EachIn to iterate through
|
|
@@ -611,7 +656,7 @@ Function MapValues:TMapEnumerator( map:TMap )
|
|
End Function
|
|
End Function
|
|
|
|
|
|
Rem
|
|
Rem
|
|
-bbdoc: Copy a map
|
|
|
|
|
|
+bbdoc: Copies a map
|
|
returns: A copy of @map
|
|
returns: A copy of @map
|
|
End Rem
|
|
End Rem
|
|
Function CopyMap:TMap( map:TMap )
|
|
Function CopyMap:TMap( map:TMap )
|