dragonflymr
Dec 21, 2015Cirrostratus
table and sort order
Hi,
From my simple test it seems that keys are listed (for example in foreach loop) in the order they were created so key created first is listed as last and key created as last first (at least with for indef indef keys).
Is that so or maybe coincidence or flaw in my test routine?
I asking this in context of deleting x number of oldest keys (when keys are indef indef). Side question is if only way to do that is to iterate through all keys and start deleting when counter hits given threshold - something like that:
set s [table keys -subtable master -count]
set keys_to_be_del 10
set start_del [expr {$s - $keys_to_be_del}]
set i 1
foreach k [table keys -subtable master] {
if {$i > $start_del} {
table delete -subtable master $k
}
incr i
}
Of course above will only work correctly if my assumption is correct 🙂
Piotr