Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
|
|
@ -0,0 +1,9 @@
|
|||
(import std.Dict)
|
||||
|
||||
(let d (dict
|
||||
"key1" "value1"
|
||||
"key2" "value2"))
|
||||
|
||||
(print (dict:entries d))
|
||||
(print (dict:keys d))
|
||||
(print (dict:values d))
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
### MAPs
|
||||
|
||||
# Since the keys of a JSON object must be strings, we'll use as an
|
||||
# example of a MAP one which has integer keys:
|
||||
|
||||
D create or replace macro amap() as (SELECT MAP( [1,2,3], ['hello', 'world', '!']));
|
||||
D select amap() "A Map";
|
||||
┌─────────────────────────┐
|
||||
│ A Map │
|
||||
│ map(integer, varchar) │
|
||||
├─────────────────────────┤
|
||||
│ {1=hello, 2=world, 3=!} │
|
||||
└─────────────────────────┘
|
||||
|
||||
# Iterating over the keys:
|
||||
|
||||
D select unnest(map_keys(amap())) as key;
|
||||
┌───────┐
|
||||
│ key │
|
||||
│ int32 │
|
||||
├───────┤
|
||||
│ 1 │
|
||||
│ 2 │
|
||||
│ 3 │
|
||||
└───────┘
|
||||
|
||||
# Iterating over the values:
|
||||
D select unnest(map_values(amap())) as value;
|
||||
┌─────────┐
|
||||
│ value │
|
||||
│ varchar │
|
||||
├─────────┤
|
||||
│ hello │
|
||||
│ world │
|
||||
│ ! │
|
||||
└─────────┘
|
||||
|
||||
# One way to generate the key-value pairs is as follows:
|
||||
D select unnest(map_keys(amap())) as key, unnest(map_values(amap())) as value;
|
||||
┌───────┬─────────┐
|
||||
│ key │ value │
|
||||
│ int32 │ varchar │
|
||||
├───────┼─────────┤
|
||||
│ 1 │ hello │
|
||||
│ 2 │ world │
|
||||
│ 3 │ ! │
|
||||
└───────┴─────────┘
|
||||
|
||||
# ... or avoiding calling amap() twice:
|
||||
|
||||
D select unnest(map_keys(m)) as key, unnest(map_values(m)) as value
|
||||
from (select amap() m);
|
||||
┌───────┬─────────┐
|
||||
│ key │ value │
|
||||
│ int32 │ varchar │
|
||||
├───────┼─────────┤
|
||||
│ 1 │ hello │
|
||||
│ 2 │ world │
|
||||
│ 3 │ ! │
|
||||
└───────┴─────────┘
|
||||
|
||||
### JSON objects
|
||||
|
||||
# For simplicity, we'll the JSON entity `amap()::JSON` as an example object:
|
||||
|
||||
D select amap()::JSON as j;
|
||||
┌───────────────────────────────────┐
|
||||
│ j │
|
||||
│ json │
|
||||
├───────────────────────────────────┤
|
||||
│ {"1":"hello","2":"world","3":"!"} │
|
||||
└───────────────────────────────────┘
|
||||
|
||||
# To find the keys of a JSON object as a list,
|
||||
# whence one can use iteration over lists:
|
||||
|
||||
D select json_keys(amap()::JSON) as keys;
|
||||
┌───────────┐
|
||||
│ keys │
|
||||
│ varchar[] │
|
||||
├───────────┤
|
||||
│ [1, 2, 3] │
|
||||
└───────────┘
|
||||
|
||||
# Similarly, to find the values in a JSON object as a list:
|
||||
|
||||
D select list_transform( json_keys(j), k -> (j->>k) ) as list
|
||||
from (select amap()::JSON as j);
|
||||
┌───────────────────┐
|
||||
│ list │
|
||||
│ varchar[] │
|
||||
├───────────────────┤
|
||||
│ [hello, world, !] │
|
||||
└───────────────────┘
|
||||
|
||||
# Show the key-value pairs as a table:
|
||||
D select unnest(json_keys(j)) as key,
|
||||
unnest(list_transform(json_keys(j), k -> (j->>k))) as value
|
||||
from (select amap()::JSON as j);
|
||||
|
||||
┌─────────┬─────────┐
|
||||
│ key │ value │
|
||||
│ varchar │ varchar │
|
||||
├─────────┼─────────┤
|
||||
│ 1 │ hello │
|
||||
│ 2 │ world │
|
||||
│ 3 │ ! │
|
||||
└─────────┴─────────┘
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
import system'collections;
|
||||
import system'routines;
|
||||
import extensions;
|
||||
|
||||
public program()
|
||||
{
|
||||
// 1. Create
|
||||
var map := Dictionary.new();
|
||||
map["key"] := "foox";
|
||||
map["key"] := "foo";
|
||||
map["key2"]:= "foo2";
|
||||
map["key3"]:= "foo3";
|
||||
map["key4"]:= "foo4";
|
||||
|
||||
// Enumerate
|
||||
map.forEach:
|
||||
(keyValue){ console.printLine(keyValue.Key," : ",keyValue.Value) }
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
class Main {
|
||||
static public function main() {
|
||||
var map = [1 => "one", 2 => "two"];
|
||||
|
||||
// key and value
|
||||
for (key => value in map) {
|
||||
trace(key + " " + value);
|
||||
}
|
||||
|
||||
// keys only
|
||||
for (key in map.keys())
|
||||
trace(key);
|
||||
|
||||
// values only
|
||||
for (value in map)
|
||||
trace(value);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
-- Create a new map with four entries.
|
||||
local capitals = {
|
||||
Greece = "Athens",
|
||||
Sweden = "Stockholm",
|
||||
Peru = "Lima",
|
||||
Uruguay = "Monevideo"
|
||||
}
|
||||
|
||||
-- Iterate through the map and print out the key/value pairs.
|
||||
for k, v in capitals do print(k, v) end
|
||||
print()
|
||||
|
||||
-- Iterate though the map and print out just the keys.
|
||||
for capitals:keys() as k do print(k) end
|
||||
print()
|
||||
|
||||
-- Iterate though the map and print out just the values.
|
||||
for capitals:values() as v do print(v) end
|
||||
print()
|
||||
|
|
@ -1,58 +1,72 @@
|
|||
/*REXX program demonstrates how to set and display values for an associative array. */
|
||||
/*╔════════════════════════════════════════════════════════════════════════════════════╗
|
||||
║ The (below) two REXX statements aren't really necessary, but it shows how to ║
|
||||
║ define any and all entries in a associative array so that if a "key" is used that ║
|
||||
║ isn't defined, it can be displayed to indicate such, or its value can be checked ║
|
||||
║ to determine if a particular associative array element has been set (defined). ║
|
||||
╚════════════════════════════════════════════════════════════════════════════════════╝*/
|
||||
stateF.= ' [not defined yet] ' /*sets any/all state former capitals.*/
|
||||
stateN.= ' [not defined yet] ' /*sets any/all state names. */
|
||||
w = 0 /*the maximum length of a state name.*/
|
||||
stateL =
|
||||
/*╔════════════════════════════════════════════════════════════════════════════════════╗
|
||||
║ The list of states (empty as of now). It's convenient to have them in alphabetic ║
|
||||
║ order; they'll be listed in the order as they are in the REXX program below). ║
|
||||
║ In REXX, when a key is used (for a stemmed array, as they are called in REXX), ║
|
||||
║ and the key isn't assigned a value, the key's name is stored (internally) as ║
|
||||
║ uppercase (Latin) characters (as in the examples below. If the key has a ║
|
||||
║ a value, the key's value is used as is (i.e.: no upper translation is performed).║
|
||||
║ Actually, any characters can be used, including blank(s) and non─displayable ║
|
||||
║ characters (including '00'x, 'ff'x, commas, periods, quotes, ···). ║
|
||||
╚════════════════════════════════════════════════════════════════════════════════════╝*/
|
||||
call setSC 'al', "Alabama" , 'Tuscaloosa'
|
||||
call setSC 'ca', "California" , 'Benicia'
|
||||
call setSC 'co', "Colorado" , 'Denver City'
|
||||
call setSC 'ct', "Connecticut" , 'Hartford and New Haven (jointly)'
|
||||
call setSC 'de', "Delaware" , 'New-Castle'
|
||||
call setSC 'ga', "Georgia" , 'Milledgeville'
|
||||
call setSC 'il', "Illinois" , 'Vandalia'
|
||||
call setSC 'in', "Indiana" , 'Corydon'
|
||||
call setSC 'ia', "Iowa" , 'Iowa City'
|
||||
call setSC 'la', "Louisiana" , 'New Orleans'
|
||||
call setSC 'me', "Maine" , 'Portland'
|
||||
call setSC 'mi', "Michigan" , 'Detroit'
|
||||
call setSC 'ms', "Mississippi" , 'Natchez'
|
||||
call setSC 'mo', "Missouri" , 'Saint Charles'
|
||||
call setSC 'mt', "Montana" , 'Virginia City'
|
||||
call setSC 'ne', "Nebraska" , 'Lancaster'
|
||||
call setSC 'nh', "New Hampshire" , 'Exeter'
|
||||
call setSC 'ny', "New York" , 'New York'
|
||||
call setSC 'nc', "North Carolina" , 'Fayetteville'
|
||||
call setSC 'oh', "Ohio" , 'Chillicothe'
|
||||
call setSC 'ok', "Oklahoma" , 'Guthrie'
|
||||
call setSC 'pa', "Pennsylvania" , 'Lancaster'
|
||||
call setSC 'sc', "South Carolina" , 'Charlestown'
|
||||
call setSC 'tn', "Tennessee" , 'Murfreesboro'
|
||||
call setSC 'vt', "Vermont" , 'Windsor'
|
||||
-- 8 Aug 2025
|
||||
include Settings
|
||||
|
||||
do j=1 for words(stateL) /*show all capitals that were defined. */
|
||||
$= word(stateL, j) /*get the next (USA) state in the list.*/
|
||||
say 'the former capital of ('$") " left(stateN.$, w) " was " stateC.$
|
||||
end /*j*/ /* [↑] show states that were defined.*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
setSC: parse arg code,name,cap; upper code /*get code, name & cap.; uppercase code*/
|
||||
stateL= stateL code /*keep a list of all the US state codes*/
|
||||
stateN.code= name; w= max(w,length(name)) /*define the state's name; max width. */
|
||||
stateC.code= cap /* " " " code to the capital*/
|
||||
return /*return to invoker, SETSC is finished.*/
|
||||
say 'ASSOCIATIVE ARRAY: ITERATION'
|
||||
say version
|
||||
say
|
||||
list=''; arra.=''; w=0
|
||||
-- States with former capitals: key, name, capital
|
||||
call SetStateCap 'al','Alabama','Tuscaloosa'
|
||||
call SetStateCap 'ca','California','Benicia'
|
||||
call SetStateCap 'co','Colorado','Denver City'
|
||||
call SetStateCap 'ct','Connecticut','Hartford and New Haven'
|
||||
call SetStateCap 'de','Delaware','New-Castle'
|
||||
call SetStateCap 'ga','Georgia','Milledgeville'
|
||||
call SetStateCap 'il','Illinois','Vandalia'
|
||||
call SetStateCap 'in','Indiana','Corydon'
|
||||
call SetStateCap 'ia','Iowa','Iowa City'
|
||||
call SetStateCap 'la','Louisiana','New Orleans'
|
||||
call SetStateCap 'me','Maine','Portland'
|
||||
call SetStateCap 'mi','Michigan','Detroit'
|
||||
call SetStateCap 'ms','Mississippi','Natchez'
|
||||
call SetStateCap 'mo','Missouri','Saint Charles'
|
||||
call SetStateCap 'mt','Montana','Virginia City'
|
||||
call SetStateCap 'ne','Nebraska','Lancaster'
|
||||
call SetStateCap 'nh','New Hampshire','Exeter'
|
||||
call SetStateCap 'ny','New York','New York'
|
||||
call SetStateCap 'nc','North Carolina','Fayetteville'
|
||||
call SetStateCap 'oh','Ohio','Chillicothe'
|
||||
call SetStateCap 'ok','Oklahoma','Guthrie'
|
||||
call SetStateCap 'pa','Pennsylvania','Lancaster'
|
||||
call SetStateCap 'sc','South Carolina','Charlestown'
|
||||
call SetStateCap 'tn','Tennessee','Murfreesboro'
|
||||
call SetStateCap 'vt','Vermont','Windsor'
|
||||
arra.0=w
|
||||
-- Loop through list
|
||||
say 'Using a list...'
|
||||
do w = 1 to words(list)
|
||||
a=Word(list,w)
|
||||
say 'The former capital of' stna.a '('a')' 'was' stca.a
|
||||
end
|
||||
say
|
||||
-- Loop through aux array...'
|
||||
say 'Using an array...'
|
||||
do w = 1 to arra.0
|
||||
a=arra.w
|
||||
say 'The former capital of' stna.a '('a')' 'was' stca.a
|
||||
end
|
||||
say
|
||||
-- Show all vars
|
||||
say 'Variables...'
|
||||
if pos('Regina',version) > 0 then
|
||||
call Library
|
||||
call SysDumpVariables
|
||||
exit
|
||||
|
||||
SetStateCap:
|
||||
parse arg code,name,cap
|
||||
code=Upper(code)
|
||||
-- Next row in associative array
|
||||
stna.code=name; stca.code=cap
|
||||
-- Track keys in a list
|
||||
list=list code
|
||||
-- Track keys in an array
|
||||
w=w+1; arra.w=code
|
||||
return
|
||||
|
||||
Library:
|
||||
call RxFuncAdd 'SysLoadFuncs','RegUtil','SysLoadFuncs'
|
||||
call SysLoadFuncs
|
||||
return
|
||||
|
||||
include Abend
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
main(params):+
|
||||
mm =: 'a' -> 1, 'b' -> 2, 'c' -> 3
|
||||
mm =: tuple mm as map
|
||||
\ iterate over the pairs, order undefined
|
||||
?# t =: map mm give pairs
|
||||
print t.1 _ '->' _ t.2 _ ' ' nonl
|
||||
print ''
|
||||
\ iterate over the keys
|
||||
?# k =: map mm give keys
|
||||
print k, ' ' nonl
|
||||
print ''
|
||||
x =: mm{'c'} \ changes order by access
|
||||
\ iterate over the values only
|
||||
?# v =: map mm give values
|
||||
print v, ' ' nonl
|
||||
print ''
|
||||
\ ordered keys:
|
||||
?# k =: map mm give keys ascending
|
||||
print k, ' ' nonl
|
||||
print ''
|
||||
\ ordered keys:
|
||||
?# k =: map mm give keys descending
|
||||
print k _ '->' _ mm{k} _ ' ' nonl
|
||||
print ''
|
||||
|
|
@ -1,16 +1,7 @@
|
|||
array set myAry {
|
||||
# list items here...
|
||||
array set family {
|
||||
surname Miller
|
||||
father John
|
||||
mother Helen
|
||||
daughter [list Jane Karen]
|
||||
son Donald
|
||||
}
|
||||
|
||||
# Iterate over keys and values
|
||||
foreach {key value} [array get myAry] {
|
||||
puts "$key -> $value"
|
||||
}
|
||||
|
||||
# Iterate over just keys
|
||||
foreach key [array names myAry] {
|
||||
puts "key = $key"
|
||||
}
|
||||
|
||||
# There is nothing for directly iterating over just the values
|
||||
# Use the keys+values version and ignore the keys
|
||||
|
|
|
|||
|
|
@ -1,16 +1,3 @@
|
|||
set myDict [dict create ...]; # Make the dictionary
|
||||
|
||||
# Iterate over keys and values
|
||||
dict for {key value} $myDict {
|
||||
puts "$key -> $value"
|
||||
}
|
||||
|
||||
# Iterate over keys
|
||||
foreach key [dict keys $myDict] {
|
||||
puts "key = $key"
|
||||
}
|
||||
|
||||
# Iterate over values
|
||||
foreach value [dict values $myDict] {
|
||||
puts "value = $value"
|
||||
}
|
||||
# "John Miller"
|
||||
set dad "$family(father) $family(lastname)"
|
||||
set second_daughter [lindex $family(daughter) 1]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
set l [array get family]
|
||||
# {surname Miller father John mother Helen daughter {Jane Karen} son Donald}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
array set myAry {
|
||||
# list items here...
|
||||
}
|
||||
|
||||
# Iterate over keys and values
|
||||
foreach {key value} [array get myAry] {
|
||||
puts "$key -> $value"
|
||||
}
|
||||
|
||||
# Iterate over just keys
|
||||
foreach key [array names myAry] {
|
||||
puts "key = $key"
|
||||
}
|
||||
|
||||
# There is nothing for directly iterating over just the values
|
||||
# Use the keys+values version and ignore the keys
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
set myDict [dict create ...]; # Make the dictionary
|
||||
|
||||
# Iterate over keys and values
|
||||
dict for {key value} $myDict {
|
||||
puts "$key -> $value"
|
||||
}
|
||||
|
||||
# Iterate over keys
|
||||
foreach key [dict keys $myDict] {
|
||||
puts "key = $key"
|
||||
}
|
||||
|
||||
# Iterate over values
|
||||
foreach value [dict values $myDict] {
|
||||
puts "value = $value"
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
var hash_map = std.StringArrayHashMap(f32).init(allocator);
|
||||
defer hash_map.deinit();
|
||||
|
||||
try hash_map.put("B3", 246.94);
|
||||
try hash_map.put("C4", 261.63);
|
||||
try hash_map.put("C#4", 277.18);
|
||||
|
||||
for (hash_map.keys()) |key| {
|
||||
try stdout.print("{s}\n", .{key});
|
||||
}
|
||||
|
||||
for (hash_map.values()) |value| {
|
||||
try stdout.print("{d}\n", .{value});
|
||||
}
|
||||
|
||||
var iter = hash_map.iterator();
|
||||
while (iter.next()) |entry| {
|
||||
const key = entry.key_ptr.*;
|
||||
const value = entry.value_ptr.*;
|
||||
|
||||
try stdout.print("{s}, {d}\n", .{key, value});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
var hash_map = std.AutoArrayHashMap(u8, []const u8).init(allocator);
|
||||
defer hash_map.deinit();
|
||||
|
||||
try hash_map.put('A', "Alpha");
|
||||
try hash_map.put('B', "Bravo");
|
||||
try hash_map.put('C', "Charlie");
|
||||
|
||||
for (hash_map.keys()) |key| {
|
||||
try stdout.print("{c}\n", .{key});
|
||||
}
|
||||
|
||||
for (hash_map.values()) |value| {
|
||||
try stdout.print("{s}\n", .{value});
|
||||
}
|
||||
|
||||
var iter = hash_map.iterator();
|
||||
while (iter.next()) |entry| {
|
||||
const key = entry.key_ptr.*;
|
||||
const value = entry.value_ptr.*;
|
||||
|
||||
try stdout.print("{c}, {s}\n", .{key, value});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue