Re: How To Build Lookup Tables

new topic     » goto parent     » topic index » view thread      » older message » newer message
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!

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu