Procházet zdrojové kódy

Added TTreeMap Clear() method.
Added more TTreeMap examples.

woollybah před 6 roky
rodič
revize
d3b6098fbd

+ 18 - 0
collections.mod/doc/ttreemap_clear.bmx

@@ -0,0 +1,18 @@
+SuperStrict
+
+Framework brl.collections
+Import brl.standardio
+
+Local openWith:TTreeMap<String, String> = New TTreeMap<String, String>
+
+openWith.Add("txt", "notepad.exe")
+openWith.Add("bmp", "paint.exe")
+openWith.Add("dib", "paint.exe")
+openWith.Add("rtf", "wordpad.exe")
+
+Print "openWith.Count() : " + openWith.Count()
+
+Print "~nopenWith.Clear()"
+openWith.Clear()
+
+Print "~nopenWith.Count() : " + openWith.Count()

+ 19 - 0
collections.mod/doc/ttreemap_containskey.bmx

@@ -0,0 +1,19 @@
+SuperStrict
+
+Framework brl.collections
+Import brl.standardio
+
+Local openWith:TTreeMap<String, String> = New TTreeMap<String, String>
+
+openWith.Add("txt", "notepad.exe")
+openWith.Add("bmp", "paint.exe")
+openWith.Add("dib", "paint.exe")
+openWith.Add("rtf", "wordpad.exe")
+
+Print "Keys:"
+For Local key:String = EachIn openWith.Keys()
+	Print key
+Next
+
+Print "~nopenWith.ContainsKey(~qbmp~q) : " + openWith.ContainsKey("bmp")
+Print "~nopenWith.ContainsKey(~qjpg~q) : " + openWith.ContainsKey("jpg")

+ 20 - 0
collections.mod/doc/ttreemap_containsvalue.bmx

@@ -0,0 +1,20 @@
+SuperStrict
+
+Framework brl.collections
+Import brl.standardio
+
+Local openWith:TTreeMap<String, String> = New TTreeMap<String, String>
+
+openWith.Add("txt", "notepad.exe")
+openWith.Add("bmp", "paint.exe")
+openWith.Add("dib", "paint.exe")
+openWith.Add("rtf", "wordpad.exe")
+
+Print "Values :"
+
+For Local value:String = EachIn openWith.Values()
+	Print value
+Next
+
+Print "~nopenWith.ContainsValue() : " + openWith.ContainsValue("paint.exe")
+Print "~nopenWith.ContainsValue() : " + openWith.ContainsValue("calc.exe")

+ 2 - 0
collections.mod/doc/ttreemap_keys.bmx

@@ -10,6 +10,8 @@ openWith.Add("bmp", "paint.exe")
 openWith.Add("dib", "paint.exe")
 openWith.Add("rtf", "wordpad.exe")
 
+Print "Keys : "
+
 For Local key:String = EachIn openWith.Keys()
 	Print key
 Next

+ 26 - 0
collections.mod/doc/ttreemap_remove.bmx

@@ -0,0 +1,26 @@
+SuperStrict
+
+Framework brl.collections
+Import brl.standardio
+
+Local openWith:TTreeMap<String, String> = New TTreeMap<String, String>
+
+openWith.Add("txt", "notepad.exe")
+openWith.Add("bmp", "paint.exe")
+openWith.Add("dib", "paint.exe")
+openWith.Add("rtf", "wordpad.exe")
+
+Print "Keys : "
+
+For Local key:String = EachIn openWith.Keys()
+	Print key
+Next
+
+Print "~nopenWith.Remove(~qbmp~q) : " + openWith.remove("bmp")
+Print "openWith.Remove(~qbmp~q) : " + openWith.remove("bmp")
+
+Print "~nKeys : "
+
+For Local key:String = EachIn openWith.Keys()
+	Print key
+Next

+ 17 - 0
collections.mod/doc/ttreemap_values.bmx

@@ -0,0 +1,17 @@
+SuperStrict
+
+Framework brl.collections
+Import brl.standardio
+
+Local openWith:TTreeMap<String, String> = New TTreeMap<String, String>
+
+openWith.Add("txt", "notepad.exe")
+openWith.Add("bmp", "paint.exe")
+openWith.Add("dib", "paint.exe")
+openWith.Add("rtf", "wordpad.exe")
+
+Print "Values : "
+
+For Local value:String = EachIn openWith.Values()
+	Print value
+Next

+ 10 - 0
collections.mod/map.bmx

@@ -46,6 +46,14 @@ Type TTreeMap<K, V> Implements IMap<K,V>
 	Method GetIterator:IIterator<TMapNode<K,V>>()
 		Return New TMapIterator<K,V>(FirstNode())
 	End Method
+	
+	Rem
+	bbdoc: Removes all elements from the #TTreeMap.
+	End Rem
+	Method Clear()
+		root = Null
+		size = 0
+	End Method
 
 	Rem
 	bbdoc: Gets the number of key/value pairs contained in the #TTreeMap.
@@ -85,6 +93,7 @@ Type TTreeMap<K, V> Implements IMap<K,V>
 
 	Rem
 	bbdoc: Adds the specified key and value to the #TTreeMap.
+	about: Throws an exception if an element with the specified key already exists.
 	End Rem
 	Method Add(key:K, value:V)
 		If FindNode(key) Then
@@ -202,6 +211,7 @@ Type TTreeMap<K, V> Implements IMap<K,V>
 
 	Rem
 	bbdoc: Sets the element with the specified key.
+	about: Unlike with #Add, if @key already exists, the current value is replaced with @value.
 	End Rem
 	Method Operator []= (key:K, value:V)
 		Local node:TMapNode<K,V> = FindNode(key)