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