Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
|
|
@ -0,0 +1,22 @@
|
|||
import ballerina/io;
|
||||
|
||||
public function main() {
|
||||
map<string> fruit = {}; // creates an empty map
|
||||
fruit["1"] = "orange"; // associates a key of "1" with "orange"
|
||||
fruit["2"] = "apple"; // associates a key of "2" with "apple"
|
||||
io:println(fruit["1"]); // retrieves the value with a key of "1" and prints it out
|
||||
_ = fruit.remove("1"); // removes the entry with a key of "1" from the map
|
||||
io:println(fruit); // prints the rest of the map
|
||||
io:println();
|
||||
map<string> capitals = { // creates a new map with three entries
|
||||
"France": "Paris",
|
||||
"Germany": "Berlin",
|
||||
"Spain": "Madrid"
|
||||
};
|
||||
capitals["Russia"] = "Moscow"; // adds another entry
|
||||
io:println(capitals["France"]); // retrieves the "France" entry and prints out its capital
|
||||
_ = capitals.remove("France"); // removes the "France" entry
|
||||
io:println(capitals); // prints all remaining entries
|
||||
io:println(capitals.length()); // prints the number of remaining entries
|
||||
io:println(capitals["Sweden"]); // prints the entry for Sweden (nothing as there isn't one)
|
||||
}
|
||||
|
|
@ -1,25 +1,22 @@
|
|||
# use array of array for this
|
||||
proc hashGet ind$ . ar$[][] item$ .
|
||||
for i to len ar$[][]
|
||||
if ar$[i][1] = ind$
|
||||
item$ = ar$[i][2]
|
||||
return
|
||||
.
|
||||
func$ hget &arr$[][] ind$ .
|
||||
for i to len arr$[][]
|
||||
if arr$[i][1] = ind$ : return arr$[i][2]
|
||||
.
|
||||
item$ = ""
|
||||
return ""
|
||||
.
|
||||
proc hashSet ind$ val$ . ar$[][] .
|
||||
for i to len ar$[][]
|
||||
if ar$[i][1] = ind$
|
||||
ar$[i][2] = val$
|
||||
proc hset &arr$[][] ind$ val$ .
|
||||
for i to len arr$[][]
|
||||
if arr$[i][1] = ind$
|
||||
arr$[i][2] = val$
|
||||
return
|
||||
.
|
||||
.
|
||||
ar$[][] &= [ ind$ val$ ]
|
||||
arr$[][] &= [ ind$ val$ ]
|
||||
.
|
||||
clothing$[][] = [ [ "type" "t-shirt" ] [ "color" "red" ] ]
|
||||
clothing$[][] &= [ "size" "xl" ]
|
||||
#
|
||||
hashSet "color" "green" clothing$[][]
|
||||
hashGet "color" clothing$[][] col$
|
||||
print col$
|
||||
print hget clothing$[][] "color"
|
||||
hset clothing$[][] "color" "green"
|
||||
print hget clothing$[][] "color"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue