Anonymous user
Hash join: Difference between revisions
→{{header|Tcl}}: Some extra notes
(→Tcl: Added implementation) |
(→{{header|Tcl}}: Some extra notes) |
||
Line 199:
=={{header|Tcl}}==
Tcl uses hash tables to implement both its associative arrays and its dictionaries.
<lang tcl>package require Tcl 8.6
# Only for lmap, which can be replaced with foreach
proc joinTables {tableA indexA tableB indexB} {
Line 211 ⟶ 213:
foreach value $tableA {
set hashmap([lindex $value $indexA]) $value
#dict version# dict set hashmap [lindex $value $indexA] $value
}
lmap value $tableB {
set key [lindex $value $indexB]
if {![info exist hashmap($key)]} continue
#dict version# if {![dict exists $hashmap $key]} continue
list $hashmap($key) $value
#dict version# list [dict get $hashmap $key] $value
}
}
|