Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -353,9 +353,9 @@ hashRemoveKey:
|
|||
ret
|
||||
szMessErrRemove: .asciz "\033[31mError remove key !!\033[0m\n"
|
||||
.align 4
|
||||
/************************************/
|
||||
/************************************/
|
||||
/* Strings case sensitive comparisons */
|
||||
/************************************/
|
||||
/************************************/
|
||||
/* x0 et x1 contains the address of strings */
|
||||
/* return 0 in x0 if equals */
|
||||
/* return -1 if string x0 < string x1 */
|
||||
|
|
|
|||
|
|
@ -342,7 +342,7 @@ szMessErrRemove: .asciz "\033[31mError remove key !!\033[0m\n"
|
|||
.align 4
|
||||
/************************************/
|
||||
/* Strings case sensitive comparisons */
|
||||
/************************************/
|
||||
/************************************/
|
||||
/* r0 et r1 contains the address of strings */
|
||||
/* return 0 in r0 if equals */
|
||||
/* return -1 if string r0 < string r1 */
|
||||
|
|
@ -355,7 +355,7 @@ comparStrings:
|
|||
ldrb r4,[r1,r2] @ byte string 2
|
||||
cmp r3,r4
|
||||
movlt r0,#-1 @ smaller
|
||||
movgt r0,#1 @ greather
|
||||
movgt r0,#1 @ greather
|
||||
bne 100f @ not equals
|
||||
cmp r3,#0 @ 0 end string ?
|
||||
moveq r0,#0 @ equals
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
with Ada.Containers.Ordered_Maps;
|
||||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
||||
with Ada.Text_IO;
|
||||
|
||||
procedure Associative_Array is
|
||||
|
||||
-- Instantiate the generic package Ada.Containers.Ordered_Maps
|
||||
|
||||
package Associative_Int is new Ada.Containers.Ordered_Maps(Unbounded_String, Integer);
|
||||
use Associative_Int;
|
||||
|
||||
Color_Map : Map;
|
||||
Color_Cursor : Cursor;
|
||||
Success : Boolean;
|
||||
Value : Integer;
|
||||
begin
|
||||
|
||||
-- Add values to the ordered map
|
||||
|
||||
Color_Map.Insert(To_Unbounded_String("Red"), 10, Color_Cursor, Success);
|
||||
Color_Map.Insert(To_Unbounded_String("Blue"), 20, Color_Cursor, Success);
|
||||
Color_Map.Insert(To_Unbounded_String("Yellow"), 5, Color_Cursor, Success);
|
||||
|
||||
-- retrieve values from the ordered map and print the value and key
|
||||
-- to the screen
|
||||
|
||||
Value := Color_Map.Element(To_Unbounded_String("Red"));
|
||||
Ada.Text_Io.Put_Line("Red:" & Integer'Image(Value));
|
||||
Value := Color_Map.Element(To_Unbounded_String("Blue"));
|
||||
Ada.Text_IO.Put_Line("Blue:" & Integer'Image(Value));
|
||||
Value := Color_Map.Element(To_Unbounded_String("Yellow"));
|
||||
Ada.Text_IO.Put_Line("Yellow:" & Integer'Image(Value));
|
||||
end Associative_Array;
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
r_put(r, "A", 33); # an integer value
|
||||
r_put(r, "C", 2.5); # a real value
|
||||
r_put(r, "B", "associative"); # a string value
|
||||
r_put(r, "A", 33); # an integer value
|
||||
r_put(r, "C", 2.5); # a real value
|
||||
r_put(r, "B", "associative"); # a string value
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
set r to {key1:"test", key2:0}
|
||||
key1 of r
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
; create a dictionary
|
||||
d: #[
|
||||
name: "john"
|
||||
surname: "doe"
|
||||
age: 34
|
||||
name: "john"
|
||||
surname: "doe"
|
||||
age: 34
|
||||
]
|
||||
|
||||
print d
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
associative_array := {key1: "value 1", "Key with spaces and non-alphanumeric characters !*+": 23}
|
||||
MsgBox % associative_array.key1
|
||||
. "`n" associative_array["Key with spaces and non-alphanumeric characters !*+"]
|
||||
. "`n" associative_array["Key with spaces and non-alphanumeric characters !*+"]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,127 @@
|
|||
; Associative arrays in AutoIt.
|
||||
; All the required functions are below the examples.
|
||||
|
||||
; Initialize an error handler to deal with any COM errors..
|
||||
global $oMyError = ObjEvent("AutoIt.Error", "AAError")
|
||||
|
||||
; first example, simple.
|
||||
global $simple
|
||||
|
||||
; Initialize your array ...
|
||||
AAInit($simple)
|
||||
|
||||
AAAdd($simple, "Appple", "fruit")
|
||||
AAAdd($simple, "Dog", "animal")
|
||||
AAAdd($simple, "Silicon", "tetravalent metalloid semiconductor")
|
||||
|
||||
ConsoleWrite("It is well-known that Silicon is a " & AAGetItem($simple, "Silicon") & "." & @CRLF)
|
||||
ConsoleWrite(@CRLF)
|
||||
|
||||
|
||||
; A more interesting example..
|
||||
|
||||
$ini_path = "AA_Test.ini"
|
||||
; Put this prefs section in your ini file..
|
||||
; [test]
|
||||
; foo=foo value
|
||||
; foo2=foo2 value
|
||||
; bar=bar value
|
||||
; bar2=bar2 value
|
||||
|
||||
|
||||
global $associative_array
|
||||
AAInit($associative_array)
|
||||
|
||||
; We are going to convert this 2D array into a cute associative array where we
|
||||
; can access the values by simply using their respective key names..
|
||||
$test_array = IniReadSection($ini_path, "test")
|
||||
|
||||
for $z = 1 to 2 ; do it twice, to show that the items are *really* there!
|
||||
for $i = 1 to $test_array[0][0]
|
||||
$key_name = $test_array[$i][0]
|
||||
ConsoleWrite("Adding '" & $key_name & "'.." & @CRLF)
|
||||
; key already exists in "$associative_array", use the pre-determined value..
|
||||
if AAExists($associative_array, $key_name) then
|
||||
$this_value = AAGetItem($associative_array, $key_name)
|
||||
ConsoleWrite("key_name ALREADY EXISTS! : =>" & $key_name & "<=" & @CRLF)
|
||||
else
|
||||
$this_value = $test_array[$i][1]
|
||||
; store left=right value pair in AA
|
||||
if $this_value then
|
||||
AAAdd($associative_array, $key_name, $this_value)
|
||||
endif
|
||||
endif
|
||||
next
|
||||
next
|
||||
|
||||
ConsoleWrite(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" & @CRLF)
|
||||
AAList($associative_array)
|
||||
|
||||
ConsoleWrite(@CRLF & "Removing 'foo'..")
|
||||
AARemove($associative_array, "foo")
|
||||
|
||||
ConsoleWrite(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" & @CRLF)
|
||||
AAList($associative_array)
|
||||
|
||||
|
||||
AAWipe($associative_array)
|
||||
|
||||
|
||||
; end
|
||||
|
||||
|
||||
|
||||
func AAInit(ByRef $dict_obj)
|
||||
$dict_obj = ObjCreate("Scripting.Dictionary")
|
||||
endfunc
|
||||
|
||||
; Adds a key and item pair to a Dictionary object..
|
||||
func AAAdd(ByRef $dict_obj, $key, $val)
|
||||
$dict_obj.Add($key, $val)
|
||||
If @error Then return SetError(1, 1, -1)
|
||||
endfunc
|
||||
|
||||
; Removes a key and item pair from a Dictionary object..
|
||||
func AARemove(ByRef $dict_obj, $key)
|
||||
$dict_obj.Remove($key)
|
||||
If @error Then return SetError(1, 1, -1)
|
||||
endfunc
|
||||
|
||||
; Returns true if a specified key exists in the associative array, false if not..
|
||||
func AAExists(ByRef $dict_obj, $key)
|
||||
return $dict_obj.Exists($key)
|
||||
endfunc
|
||||
|
||||
; Returns a value for a specified key name in the associative array..
|
||||
func AAGetItem(ByRef $dict_obj, $key)
|
||||
return $dict_obj.Item($key)
|
||||
endfunc
|
||||
|
||||
; Returns the total number of keys in the array..
|
||||
func AACount(ByRef $dict_obj)
|
||||
return $dict_obj.Count
|
||||
endfunc
|
||||
|
||||
; List all the "Key" > "Item" pairs in the array..
|
||||
func AAList(ByRef $dict_obj)
|
||||
ConsoleWrite("AAList: =>" & @CRLF)
|
||||
local $k = $dict_obj.Keys ; Get the keys
|
||||
; local $a = $dict_obj.Items ; Get the items (for reference)
|
||||
for $i = 0 to AACount($dict_obj) -1 ; Iterate the array
|
||||
ConsoleWrite($k[$i] & " ==> " & AAGetItem($dict_obj, $k[$i]) & @CRLF)
|
||||
next
|
||||
endfunc
|
||||
|
||||
; Wipe the array, obviously.
|
||||
func AAWipe(ByRef $dict_obj)
|
||||
$dict_obj.RemoveAll()
|
||||
endfunc
|
||||
|
||||
; Oh oh!
|
||||
func AAError()
|
||||
Local $err = $oMyError.number
|
||||
If $err = 0 Then $err = -1
|
||||
SetError($err) ; to check for after this function returns
|
||||
endfunc
|
||||
|
||||
;; End AA Functions.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
pprop "animals "cat 5
|
||||
pprop "animals "dog 4
|
||||
pprop "animals "mouse 11
|
||||
print gprop "animals "cat ; 5
|
||||
remprop "animals "dog
|
||||
show plist "animals ; [mouse 11 cat 5]
|
||||
|
|
@ -1,36 +1,36 @@
|
|||
import ceylon.collection {
|
||||
|
||||
ArrayList,
|
||||
HashMap,
|
||||
naturalOrderTreeMap
|
||||
ArrayList,
|
||||
HashMap,
|
||||
naturalOrderTreeMap
|
||||
}
|
||||
|
||||
shared void run() {
|
||||
|
||||
// the easiest way is to use the map function to create
|
||||
// an immutable map
|
||||
value myMap = map {
|
||||
"foo" -> 5,
|
||||
"bar" -> 10,
|
||||
"baz" -> 15,
|
||||
"foo" -> 6 // by default the first "foo" will remain
|
||||
};
|
||||
|
||||
// or you can use the HashMap constructor to create
|
||||
// a mutable one
|
||||
value myOtherMap = HashMap {
|
||||
"foo"->"bar"
|
||||
};
|
||||
myOtherMap.put("baz", "baxx");
|
||||
|
||||
// there's also a sorted red/black tree map
|
||||
value myTreeMap = naturalOrderTreeMap {
|
||||
1 -> "won",
|
||||
2 -> "too",
|
||||
4 -> "fore"
|
||||
};
|
||||
for(num->homophone in myTreeMap) {
|
||||
print("``num`` is ``homophone``");
|
||||
}
|
||||
|
||||
|
||||
// the easiest way is to use the map function to create
|
||||
// an immutable map
|
||||
value myMap = map {
|
||||
"foo" -> 5,
|
||||
"bar" -> 10,
|
||||
"baz" -> 15,
|
||||
"foo" -> 6 // by default the first "foo" will remain
|
||||
};
|
||||
|
||||
// or you can use the HashMap constructor to create
|
||||
// a mutable one
|
||||
value myOtherMap = HashMap {
|
||||
"foo"->"bar"
|
||||
};
|
||||
myOtherMap.put("baz", "baxx");
|
||||
|
||||
// there's also a sorted red/black tree map
|
||||
value myTreeMap = naturalOrderTreeMap {
|
||||
1 -> "won",
|
||||
2 -> "too",
|
||||
4 -> "fore"
|
||||
};
|
||||
for(num->homophone in myTreeMap) {
|
||||
print("``num`` is ``homophone``");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
// arr is an array of string to int. any type can be used in both places.
|
||||
var keys: domain(string);
|
||||
var arr: [keys] int;
|
||||
|
||||
// keys can be added to a domain using +, new values will be initialized to the default value (0 for int)
|
||||
keys += "foo";
|
||||
keys += "bar";
|
||||
keys += "baz";
|
||||
|
||||
// array access via [] or ()
|
||||
arr["foo"] = 1;
|
||||
arr["bar"] = 4;
|
||||
arr("baz") = 6;
|
||||
|
||||
// write auto-formats domains and arrays
|
||||
writeln("Keys: ", keys);
|
||||
writeln("Values: ", arr);
|
||||
|
||||
// keys can be deleted using -
|
||||
keys -= "bar";
|
||||
|
||||
writeln("Keys: ", keys);
|
||||
writeln("Values: ", arr);
|
||||
|
||||
// chapel also supports array literals
|
||||
var arr2 = [ "John" => 3, "Pete" => 14 ];
|
||||
|
||||
writeln("arr2 keys: ", arr2.domain);
|
||||
writeln("arr2 values: ", arr2);
|
||||
|
|
@ -1,67 +1,67 @@
|
|||
DEFINITION Collections;
|
||||
|
||||
IMPORT Boxes;
|
||||
IMPORT Boxes;
|
||||
|
||||
CONST
|
||||
notFound = -1;
|
||||
CONST
|
||||
notFound = -1;
|
||||
|
||||
TYPE
|
||||
Hash = POINTER TO RECORD
|
||||
cap-, size-: INTEGER;
|
||||
(h: Hash) ContainsKey (k: Boxes.Object): BOOLEAN, NEW;
|
||||
(h: Hash) Get (k: Boxes.Object): Boxes.Object, NEW;
|
||||
(h: Hash) IsEmpty (): BOOLEAN, NEW;
|
||||
(h: Hash) Put (k, v: Boxes.Object): Boxes.Object, NEW;
|
||||
(h: Hash) Remove (k: Boxes.Object): Boxes.Object, NEW;
|
||||
(h: Hash) Reset, NEW
|
||||
END;
|
||||
TYPE
|
||||
Hash = POINTER TO RECORD
|
||||
cap-, size-: INTEGER;
|
||||
(h: Hash) ContainsKey (k: Boxes.Object): BOOLEAN, NEW;
|
||||
(h: Hash) Get (k: Boxes.Object): Boxes.Object, NEW;
|
||||
(h: Hash) IsEmpty (): BOOLEAN, NEW;
|
||||
(h: Hash) Put (k, v: Boxes.Object): Boxes.Object, NEW;
|
||||
(h: Hash) Remove (k: Boxes.Object): Boxes.Object, NEW;
|
||||
(h: Hash) Reset, NEW
|
||||
END;
|
||||
|
||||
HashMap = POINTER TO RECORD
|
||||
cap-, size-: INTEGER;
|
||||
(hm: HashMap) ContainsKey (k: Boxes.Object): BOOLEAN, NEW;
|
||||
(hm: HashMap) ContainsValue (v: Boxes.Object): BOOLEAN, NEW;
|
||||
(hm: HashMap) Get (k: Boxes.Object): Boxes.Object, NEW;
|
||||
(hm: HashMap) IsEmpty (): BOOLEAN, NEW;
|
||||
(hm: HashMap) Keys (): POINTER TO ARRAY OF Boxes.Object, NEW;
|
||||
(hm: HashMap) Put (k, v: Boxes.Object): Boxes.Object, NEW;
|
||||
(hm: HashMap) Remove (k: Boxes.Object): Boxes.Object, NEW;
|
||||
(hm: HashMap) Reset, NEW;
|
||||
(hm: HashMap) Values (): POINTER TO ARRAY OF Boxes.Object, NEW
|
||||
END;
|
||||
HashMap = POINTER TO RECORD
|
||||
cap-, size-: INTEGER;
|
||||
(hm: HashMap) ContainsKey (k: Boxes.Object): BOOLEAN, NEW;
|
||||
(hm: HashMap) ContainsValue (v: Boxes.Object): BOOLEAN, NEW;
|
||||
(hm: HashMap) Get (k: Boxes.Object): Boxes.Object, NEW;
|
||||
(hm: HashMap) IsEmpty (): BOOLEAN, NEW;
|
||||
(hm: HashMap) Keys (): POINTER TO ARRAY OF Boxes.Object, NEW;
|
||||
(hm: HashMap) Put (k, v: Boxes.Object): Boxes.Object, NEW;
|
||||
(hm: HashMap) Remove (k: Boxes.Object): Boxes.Object, NEW;
|
||||
(hm: HashMap) Reset, NEW;
|
||||
(hm: HashMap) Values (): POINTER TO ARRAY OF Boxes.Object, NEW
|
||||
END;
|
||||
|
||||
LinkedList = POINTER TO RECORD
|
||||
first-, last-: Node;
|
||||
size-: INTEGER;
|
||||
(ll: LinkedList) Add (item: Boxes.Object), NEW;
|
||||
(ll: LinkedList) Append (item: Boxes.Object), NEW;
|
||||
(ll: LinkedList) AsString (): POINTER TO ARRAY OF CHAR, NEW;
|
||||
(ll: LinkedList) Contains (item: Boxes.Object): BOOLEAN, NEW;
|
||||
(ll: LinkedList) Get (at: INTEGER): Boxes.Object, NEW;
|
||||
(ll: LinkedList) IndexOf (item: Boxes.Object): INTEGER, NEW;
|
||||
(ll: LinkedList) Insert (at: INTEGER; item: Boxes.Object), NEW;
|
||||
(ll: LinkedList) IsEmpty (): BOOLEAN, NEW;
|
||||
(ll: LinkedList) Remove (item: Boxes.Object), NEW;
|
||||
(ll: LinkedList) RemoveAt (at: INTEGER), NEW;
|
||||
(ll: LinkedList) Reset, NEW;
|
||||
(ll: LinkedList) Set (at: INTEGER; item: Boxes.Object), NEW
|
||||
END;
|
||||
LinkedList = POINTER TO RECORD
|
||||
first-, last-: Node;
|
||||
size-: INTEGER;
|
||||
(ll: LinkedList) Add (item: Boxes.Object), NEW;
|
||||
(ll: LinkedList) Append (item: Boxes.Object), NEW;
|
||||
(ll: LinkedList) AsString (): POINTER TO ARRAY OF CHAR, NEW;
|
||||
(ll: LinkedList) Contains (item: Boxes.Object): BOOLEAN, NEW;
|
||||
(ll: LinkedList) Get (at: INTEGER): Boxes.Object, NEW;
|
||||
(ll: LinkedList) IndexOf (item: Boxes.Object): INTEGER, NEW;
|
||||
(ll: LinkedList) Insert (at: INTEGER; item: Boxes.Object), NEW;
|
||||
(ll: LinkedList) IsEmpty (): BOOLEAN, NEW;
|
||||
(ll: LinkedList) Remove (item: Boxes.Object), NEW;
|
||||
(ll: LinkedList) RemoveAt (at: INTEGER), NEW;
|
||||
(ll: LinkedList) Reset, NEW;
|
||||
(ll: LinkedList) Set (at: INTEGER; item: Boxes.Object), NEW
|
||||
END;
|
||||
|
||||
Vector = POINTER TO RECORD
|
||||
size-, cap-: LONGINT;
|
||||
(v: Vector) Add (item: Boxes.Object), NEW;
|
||||
(v: Vector) AddAt (item: Boxes.Object; i: INTEGER), NEW;
|
||||
(v: Vector) Contains (o: Boxes.Object): BOOLEAN, NEW;
|
||||
(v: Vector) Get (i: LONGINT): Boxes.Object, NEW;
|
||||
(v: Vector) IndexOf (o: Boxes.Object): LONGINT, NEW;
|
||||
(v: Vector) Remove (o: Boxes.Object), NEW;
|
||||
(v: Vector) RemoveIndex (i: LONGINT): Boxes.Object, NEW;
|
||||
(v: Vector) Set (i: LONGINT; o: Boxes.Object): Boxes.Object, NEW;
|
||||
(v: Vector) Trim, NEW
|
||||
END;
|
||||
Vector = POINTER TO RECORD
|
||||
size-, cap-: LONGINT;
|
||||
(v: Vector) Add (item: Boxes.Object), NEW;
|
||||
(v: Vector) AddAt (item: Boxes.Object; i: INTEGER), NEW;
|
||||
(v: Vector) Contains (o: Boxes.Object): BOOLEAN, NEW;
|
||||
(v: Vector) Get (i: LONGINT): Boxes.Object, NEW;
|
||||
(v: Vector) IndexOf (o: Boxes.Object): LONGINT, NEW;
|
||||
(v: Vector) Remove (o: Boxes.Object), NEW;
|
||||
(v: Vector) RemoveIndex (i: LONGINT): Boxes.Object, NEW;
|
||||
(v: Vector) Set (i: LONGINT; o: Boxes.Object): Boxes.Object, NEW;
|
||||
(v: Vector) Trim, NEW
|
||||
END;
|
||||
|
||||
PROCEDURE NewHash (cap: INTEGER): Hash;
|
||||
PROCEDURE NewHashMap (cap: INTEGER): HashMap;
|
||||
PROCEDURE NewLinkedList (): LinkedList;
|
||||
PROCEDURE NewVector (cap: INTEGER): Vector;
|
||||
PROCEDURE NewHash (cap: INTEGER): Hash;
|
||||
PROCEDURE NewHashMap (cap: INTEGER): HashMap;
|
||||
PROCEDURE NewLinkedList (): LinkedList;
|
||||
PROCEDURE NewVector (cap: INTEGER): Vector;
|
||||
|
||||
END Collections.
|
||||
|
|
|
|||
|
|
@ -3,20 +3,20 @@ IMPORT StdLog, Collections, Boxes;
|
|||
|
||||
PROCEDURE Do*;
|
||||
VAR
|
||||
hm : Collections.HashMap;
|
||||
o : Boxes.Object;
|
||||
keys, values: POINTER TO ARRAY OF Boxes.Object;
|
||||
i: INTEGER;
|
||||
|
||||
hm : Collections.HashMap;
|
||||
o : Boxes.Object;
|
||||
keys, values: POINTER TO ARRAY OF Boxes.Object;
|
||||
i: INTEGER;
|
||||
|
||||
BEGIN
|
||||
hm := Collections.NewHashMap(1009);
|
||||
o := hm.Put(Boxes.NewString("first"),Boxes.NewInteger(1));
|
||||
o := hm.Put(Boxes.NewString("second"),Boxes.NewInteger(2));
|
||||
o := hm.Put(Boxes.NewString("third"),Boxes.NewInteger(3));
|
||||
o := hm.Put(Boxes.NewString("one"),Boxes.NewInteger(1));
|
||||
|
||||
StdLog.String("size: ");StdLog.Int(hm.size);StdLog.Ln;
|
||||
|
||||
hm := Collections.NewHashMap(1009);
|
||||
o := hm.Put(Boxes.NewString("first"),Boxes.NewInteger(1));
|
||||
o := hm.Put(Boxes.NewString("second"),Boxes.NewInteger(2));
|
||||
o := hm.Put(Boxes.NewString("third"),Boxes.NewInteger(3));
|
||||
o := hm.Put(Boxes.NewString("one"),Boxes.NewInteger(1));
|
||||
|
||||
StdLog.String("size: ");StdLog.Int(hm.size);StdLog.Ln;
|
||||
|
||||
END Do;
|
||||
|
||||
END BbtAssociativeArrays.
|
||||
|
|
|
|||
|
|
@ -1,34 +1,34 @@
|
|||
main() {
|
||||
var rosettaCode = { // Type is inferred to be Map<String, String>
|
||||
'task': 'Associative Array Creation'
|
||||
};
|
||||
var rosettaCode = { // Type is inferred to be Map<String, String>
|
||||
'task': 'Associative Array Creation'
|
||||
};
|
||||
|
||||
rosettaCode['language'] = 'Dart';
|
||||
rosettaCode['language'] = 'Dart';
|
||||
|
||||
// The update function can be used to update a key using a callback
|
||||
rosettaCode.update( 'is fun', // Key to update
|
||||
(value) => "i don't know", // New value to use if key is present
|
||||
ifAbsent: () => 'yes!' // Value to use if key is absent
|
||||
);
|
||||
|
||||
assert( rosettaCode.toString() == '{task: Associative Array Creation, language: Dart, is fun: yes!}');
|
||||
|
||||
// If we type the Map with dynamic keys and values, it is like a JavaScript object
|
||||
Map<dynamic, dynamic> jsObject = {
|
||||
'key': 'value',
|
||||
1: 2,
|
||||
1.5: [ 'more', 'stuff' ],
|
||||
#doStuff: () => print('doing stuff!') // #doStuff is a symbol, only one instance of this exists in the program. Would be :doStuff in Ruby
|
||||
};
|
||||
// The update function can be used to update a key using a callback
|
||||
rosettaCode.update( 'is fun', // Key to update
|
||||
(value) => "i don't know", // New value to use if key is present
|
||||
ifAbsent: () => 'yes!' // Value to use if key is absent
|
||||
);
|
||||
|
||||
print( jsObject['key'] );
|
||||
print( jsObject[1] );
|
||||
|
||||
for ( var value in jsObject[1.5] )
|
||||
print('item: $value');
|
||||
assert( rosettaCode.toString() == '{task: Associative Array Creation, language: Dart, is fun: yes!}');
|
||||
|
||||
jsObject[ #doStuff ](); // Calling the function
|
||||
|
||||
print('\nKey types:');
|
||||
jsObject.keys.forEach( (key) => print( key.runtimeType ) );
|
||||
// If we type the Map with dynamic keys and values, it is like a JavaScript object
|
||||
Map<dynamic, dynamic> jsObject = {
|
||||
'key': 'value',
|
||||
1: 2,
|
||||
1.5: [ 'more', 'stuff' ],
|
||||
#doStuff: () => print('doing stuff!') // #doStuff is a symbol, only one instance of this exists in the program. Would be :doStuff in Ruby
|
||||
};
|
||||
|
||||
print( jsObject['key'] );
|
||||
print( jsObject[1] );
|
||||
|
||||
for ( var value in jsObject[1.5] )
|
||||
print('item: $value');
|
||||
|
||||
jsObject[ #doStuff ](); // Calling the function
|
||||
|
||||
print('\nKey types:');
|
||||
jsObject.keys.forEach( (key) => print( key.runtimeType ) );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ func$ hget &arr$[][] ind$ .
|
|||
for i to len arr$[][]
|
||||
if arr$[i][1] = ind$ : return arr$[i][2]
|
||||
.
|
||||
return ""
|
||||
return ""
|
||||
.
|
||||
proc hset &arr$[][] ind$ val$ .
|
||||
for i to len arr$[][]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
(setq my-table (make-hash-table))
|
||||
(puthash 'key 'value my-table)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(setq my-table (make-hash-table :test 'equal))
|
||||
(puthash "key" 123 my-table)
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import gleam/dict
|
||||
|
||||
pub fn main() {
|
||||
// create empty dictionary
|
||||
let _ = dict.new()
|
||||
|
||||
// create dictionary from list of tuples
|
||||
let stuff = dict.from_list([#("key1", 1), #("key2", 2)])
|
||||
|
||||
// retrieve value at key
|
||||
let _ = dict.get(stuff, "key1")
|
||||
|
||||
// add key-value pair
|
||||
let _new_dict = dict.insert(stuff, "key3", 3)
|
||||
|
||||
// test key existence
|
||||
let _ = dict.has_key(stuff, "key1")
|
||||
}
|
||||
|
|
@ -19,5 +19,5 @@ delete(x, "foo")
|
|||
|
||||
// make a map with a literal
|
||||
x = map[string]int{
|
||||
"foo": 2, "bar": 42, "baz": -1,
|
||||
"foo": 2, "bar": 42, "baz": -1,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
class Main {
|
||||
static public function main() {
|
||||
var map = [1 => "one", 2 => "two"];
|
||||
trace(map);
|
||||
$type(map);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,12 +7,12 @@ Connection relates various texts to one number. The verb to be connected to impl
|
|||
"baz" is connected to 56.
|
||||
|
||||
When play begins:
|
||||
[change values]
|
||||
now "bleck" is connected to 78;
|
||||
[check values]
|
||||
if "foo" is connected to 12, say "good.";
|
||||
if "bar" is not connected to 56, say "good.";
|
||||
[retrieve values]
|
||||
let V be the number that "baz" relates to by the connection relation;
|
||||
say "'baz' => [V].";
|
||||
end the story.
|
||||
[change values]
|
||||
now "bleck" is connected to 78;
|
||||
[check values]
|
||||
if "foo" is connected to 12, say "good.";
|
||||
if "bar" is not connected to 56, say "good.";
|
||||
[retrieve values]
|
||||
let V be the number that "baz" relates to by the connection relation;
|
||||
say "'baz' => [V].";
|
||||
end the story.
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
Hash Bar is a room.
|
||||
|
||||
When play begins:
|
||||
let R be a various-to-one relation of texts to numbers;
|
||||
[initialize the relation]
|
||||
now R relates "foo" to 12;
|
||||
now R relates "bar" to 34;
|
||||
now R relates "baz" to 56;
|
||||
[check values]
|
||||
if R relates "foo" to 12, say "good.";
|
||||
if R does not relate "bar" to 56, say "good.";
|
||||
[retrieve values]
|
||||
let V be the number that "baz" relates to by R;
|
||||
say "'baz' => [V].";
|
||||
end the story.
|
||||
let R be a various-to-one relation of texts to numbers;
|
||||
[initialize the relation]
|
||||
now R relates "foo" to 12;
|
||||
now R relates "bar" to 34;
|
||||
now R relates "baz" to 56;
|
||||
[check values]
|
||||
if R relates "foo" to 12, say "good.";
|
||||
if R does not relate "bar" to 56, say "good.";
|
||||
[retrieve values]
|
||||
let V be the number that "baz" relates to by R;
|
||||
say "'baz' => [V].";
|
||||
end the story.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
Map m = [key1:'value1', key2:'value2']
|
||||
def x = ['key 1':1, 'key 2':2]
|
||||
def empty = [:]
|
||||
empty['key'] = 'value'
|
||||
empty += [key2:'value2']
|
||||
|
|
@ -5,9 +5,9 @@ local(mymap = map)
|
|||
|
||||
// Define a map with content
|
||||
local(mymap = map(
|
||||
'one' = 'Monday',
|
||||
'2' = 'Tuesday',
|
||||
3 = 'Wednesday'
|
||||
'one' = 'Monday',
|
||||
'2' = 'Tuesday',
|
||||
3 = 'Wednesday'
|
||||
))
|
||||
|
||||
// add elements to an existing map
|
||||
|
|
@ -25,14 +25,14 @@ local(mymap = map(
|
|||
|
||||
// Iterate thru a map and get values
|
||||
with v in #mymap do {^
|
||||
#v
|
||||
'<br />'
|
||||
#v
|
||||
'<br />'
|
||||
^}
|
||||
// Tuesday<br />Thursday<br />Monday<br />Wednesday<br />
|
||||
|
||||
// Perform actions on each value of a map
|
||||
#mymap -> foreach => {
|
||||
#1 -> uppercase
|
||||
#1 -> reverse
|
||||
#1 -> uppercase
|
||||
#1 -> reverse
|
||||
}
|
||||
#mymap // map(2 = YADSEUT, fourth = YADSRUHT, one = YADNOM, 3 = YADSENDEW)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
hash = [];
|
||||
hash = setfield(hash,'a',1);
|
||||
hash = setfield(hash,'b',2);
|
||||
hash = setfield(hash,'a',1);
|
||||
hash = setfield(hash,'b',2);
|
||||
hash = setfield(hash,'C',[3,4,5]);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
hash.('a') = 1;
|
||||
hash.('b') = 2;
|
||||
hash.('a') = 1;
|
||||
hash.('b') = 2;
|
||||
hash.('C') = [3,4,5];
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
$hashtable = @{}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
$hashtable = @{
|
||||
"key1" = "value 1"
|
||||
key2 = 5 # if the key name has no spaces, no quotes are needed.
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
$hashtable.foo = "bar"
|
||||
$hashtable['bar'] = 42
|
||||
$hashtable."a b" = 3.14 # keys can contain spaces, property-style access needs quotation marks, then
|
||||
$hashtable[5] = 8 # keys don't need to be strings
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# Case insensitive keys, both end up as the same key:
|
||||
$h=@{}
|
||||
$h['a'] = 1
|
||||
$h['A'] = 2
|
||||
$h
|
||||
|
||||
Name Value
|
||||
---- -----
|
||||
a 2
|
||||
|
||||
# Case sensitive keys:
|
||||
$h = New-Object -TypeName System.Collections.Hashtable
|
||||
$h['a'] = 1
|
||||
$h['A'] = 2
|
||||
$h
|
||||
|
||||
Name Value
|
||||
---- -----
|
||||
A 2
|
||||
a 1
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$hashtable.key1 # value 1
|
||||
$hashtable['key2'] # 5
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
$obj = [PSCustomObject]@{
|
||||
"key1" = "value 1"
|
||||
key2 = 5
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
-- 23 Aug 2025
|
||||
-- 21 Feb 2026
|
||||
include Setting
|
||||
|
||||
say 'ASSOCIATIVE ARRAY: CREATION'
|
||||
|
|
@ -12,7 +12,7 @@ cap.uk='London'
|
|||
call Capital 'BE'
|
||||
call Capital 'UK'
|
||||
call Capital 'NO'
|
||||
day.='Unknown'; week.=day.
|
||||
day.='Unknown'; week.='Unknown'
|
||||
day.jan.2=2; week.jan.2=1
|
||||
day.mar.17=76; week.mar.17=12
|
||||
day.aug.7=219; week.aug.7=32
|
||||
|
|
@ -31,7 +31,7 @@ a2=a1; say 'a.'a2 '=' a.a2
|
|||
a1='└┴┬├─┼'; a.a1='special characters'
|
||||
a2=a1; say 'a.'a2 '=' a.a2
|
||||
say
|
||||
call DumpVariables
|
||||
call Showvars
|
||||
exit
|
||||
|
||||
Capital:
|
||||
|
|
@ -44,4 +44,5 @@ arg mm,dd
|
|||
say mm dd 'is day no' day.mm.dd 'and week no' week.mm.dd
|
||||
return
|
||||
|
||||
-- Showvars
|
||||
include Math
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
;; Using Rebol3!
|
||||
data: #[user: "Rebol" pass: "qwerty"]
|
||||
;; or from block
|
||||
data: make map! [user: "Rebol" pass: "qwerty"]
|
||||
;; to append key...
|
||||
data/age: 23
|
||||
print ["User" data/user "has password:" data/pass "and age:" data/age]
|
||||
;; to remove key...
|
||||
remove/key data 'age ;== #[user: "Rebol" pass: "qwerty"]
|
||||
;; retrieving not existing key returns none
|
||||
data/not-exists ;== #(none)
|
||||
;; to test if key exists...
|
||||
did find data 'user ;== #(true)
|
||||
did find data 'xxxx ;== #(false)
|
||||
;; to get number of keys:
|
||||
length? data ;== 2
|
||||
;; to get keys...
|
||||
keys-of data ;== [user pass]
|
||||
;; to get values...
|
||||
values-of data ;== ["Rebol" "qwerty"]
|
||||
;; to clear the map...
|
||||
clear data ;== #[]
|
||||
|
||||
;; keys may be any value type
|
||||
append data ["a" 1 "b" 2] ;== #["a" 1 "b" 2]
|
||||
;; when used key with same name multiple times...
|
||||
append data ["b" 3 "b" 4] ;== #["a" 1 "b" 4]
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
data: dict { "name" "John" "age" 30 }
|
||||
print data -> "name"
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
t = table()
|
||||
t<"red"> = "#ff0000"
|
||||
t<"green"> = "#00ff00"
|
||||
t<"blue"> = "#0000ff"
|
||||
t = table()
|
||||
t<"red"> = "#ff0000"
|
||||
t<"green"> = "#00ff00"
|
||||
t<"blue"> = "#0000ff"
|
||||
|
||||
output = t<"red">
|
||||
output = t<"blue">
|
||||
output = t<"green">
|
||||
output = t<"red">
|
||||
output = t<"blue">
|
||||
output = t<"green">
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using Gee;
|
||||
|
||||
void main(){
|
||||
var map = new HashMap<string, int>(); // creates a HashMap with keys of type string, and values of type int
|
||||
var map = new HashMap<string, int>(); // creates a HashMap with keys of type string, and values of type int
|
||||
|
||||
// two methods to set key,value pair
|
||||
map["one"] = 1;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ k = 1
|
|||
FOR EACH o IN loCol FOXOBJECT
|
||||
? o, loCol.GetKey(k)
|
||||
k = k + 1
|
||||
ENDFOR
|
||||
ENDFOR
|
||||
*!* Get an item by its key
|
||||
? loCol("O")
|
||||
?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue