I'm going to have an array. I know the column positions & what is in each
column. I am going to perform searches. I need this to be as efficient as
possible, so I was hoping that there was an array command I didn't know that
essentially allowed me to specify 2 criteria:
1. the column in which the data I'm searching for is expected to be
2. the data i'm searching for
So far, I've only found commands that allow searching throughout the entire
array. Some of my arrays will be rather large, so I'm hoping that TCL
provides a facility for specifying the column I want to search.
Also, the array index will be arbitrarily assigned, starting at 1.
Thank you in advance for your help!
You could use a database like Metakit for your data, it's fast and
efficient for this kind of stuff.
Tcl uses hash tables as arrays, so searches are fast in one direction
key->data. In tcl8.5 dictionaries will come as new data type similar to
arrays, which may be more lightweight for the things you want.
Your notation of column is not really useful. Tcl does not have
multi-dimensional arrays, so there only is one column, but you can
simulate many, by a naming convention.
Michael
I'm not sure I understand you correctly. Is this what you want?
# Fill array
foreach {row_key row_data} $rowlist {
foreach {col_key col_data} [get_column_list_from_row $row_data] {
set my_array(${row_key},$col_key) $col_data
}
}
# Search for data in column "col_key":
foreach key [array names my_array *,$col_key] {
if {[string equal $data $my_array($key)]} {
puts "Yeah, found \"$data\" in my_array($key)"
}
}
Best regards
Ulrich
--
SIGOS Systemintegration GmbH
- TESTING IS OUR COMPETENCE -
Fon +49 911 95168-0
www.sigos.de
Tcl 'arrays' are NOT what C would call arrays. They are *unordered*
hash tables (well 'hash' order). They don't have rows or columns, just
keys and values. For example:
set x(1,2) foo
does NOT set the second element of column 1 to foo. It stores foo at
the index of the hash key '1,2' ('1,2' is a three character *string*,
NOT a pair of integers). Note:
set x(hello) goodbye
This stores the string 'goodbye' at the hash index for the hash key
'hello'.
In the sense that C or FORTRAN or BASIC or Pascal have arrays, Tcl does
NOT have arrays. Tcl has two grouping structures: lists and hash
tables. Tcl nominclature is a bit confusing to newbies, since it calls
its hash tables 'arrays'.
">
">
">
Lists are pretty close to C arrays, since C doesn't have
multi-dimentional arrays either. :-)
--
Darren New, San Diego CA USA (PST)
Things to be thankful for, #187:
There is no Chinese tradition of changing from
shoes to slippers to get off an escalator.
You can invert an array index easily.
foreach {subscript value} [array get array] {
lappend inverted($value) $subscripted
}
--
Derk Gwen http://derkgwen.250free.com/html/index.html
Quit killing people. That's high profile.
> I'm going to have an array. I know the column positions & what is in each
> column. I am going to perform searches. I need this to be as efficient as
> possible,
Arrays in Tcl aren't multi-dimensional.
> Also, the array index will be arbitrarily assigned, starting at 1.
Arrays in Tcl take arbitrary strings as keys; they are not really
indices. It sounds like you want a nested list structure!
[list [list a b c] [list 1 2 3] [list doh! ray mee]]
There have been recent upgrades to some Tcl list-handling commands
for increased ease and efficiency manipulating nested lists. Now
lindex takes multiple indices for looking up values in multi-dimensional
lists ( [lindex $above 2 0] -> "doh! ), as does lset for setting
elements. lsort can be used with -command for multidimensional
lists. lsearch seems to have no facility, but I wonder if some
additions are proposed and forthcoming. Anybody?
There are also Tcl packages that implement various structures
with better performance. (The only one I've used is BLT and its
arrays.)
Donald Arseneau as...@triumf.ca