Re: How To Build Lookup Tables
- Posted by euphoric (admin) Sep 29, 2019
- 969 views
Spock said...
Is the data actually sitting in nested sequences "hundreds of levels deep" or is it more like a 2-d table where there are hundreds of semantic levels?
It's not actually that deep. But it could be, someday.
I wrote this for now (since I'm only using tables with two columns at the moment):
namespace tables -- functions for manipulating columnar data (tables) public function new(sequence data = {{},{}}) return data end function public function lookup(object item, sequence data) integer i = find(item,data[1]) if i = 0 then return {0,{}} end if return {1,data[2][i]} end function public function set(sequence table, object key, object val = {}) integer i = find(key,table[1]) if i then table[2][i] = val else table[1] = append(table[1],key) table[2] = append(table[2],val) end if return table end function /* -- looks like <eucode> doesn't handle this comment block properly include std/map.e include std/console.e sequence table = tables:new() table = set(table,"a",123) table = set(table,"b","Billy") table = set(table,"c",{247,'x',{1,7,7}}) table = set(table,"x","Hawaii") table = set(table,"y",77897) table = set(table,"z",map:new()) display(lookup("c",table)) wait_key() */
Any enhancements are welcome!