lsearch -command tclcmd -group grpsize, lsort -group grpsiz
Closed747083ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 17 years ago
Descriptionplain2003-06-01 17:17:57
improve lsearch by adding a -command tclcmd option
to search list items using the same function as lsort
e.g.
set L [lsort -command CompareVector $L]
set X [lsearch -sorted -command CompareVector $L]
also some grouping would be great:
think you have a list with every 4 items belong to a
group and you wanna sort it by the third item:
e.g.
set L { a0 a1 a2 a3 b0 b1 b2 b3 c0 c1 c2 c3 .. }
to sort using lsort you have to make a list of lists by
set L2 {}
foreach {a b c d} { lappend L2 [list $a $b $c $d] }
set L2 [lsort -index 2 $L2]
set L [concat $L2]
a faster approach with the nonexisting -group option
set L [lsort -group 4 -index 2 $L]
searching such lists is required than as well so
lsearch -group 4 -index 2 $L c2
will return 2 the group number (my favourite, or 10 as the
real index, or 8 as the first member of the group)
such grouped lists are very general in my opinion,
because regexp,array get,split are functions that may
return such lists
finally a quick "lreverse list" command would be a nice
idea.
dkf Ticket [747083ffff]: 2 changes
[History diff]2003-06-02 17:56:20
mic42plain2003-08-15 13:41:09
Logged In: YES user_id=302287 The TIP #127 implementation could help with a part of this internally. Implementing -group could basically consists of a preprocessing step to create sublists for internal use, that get flattend out after searching or sorting is done. Could give quite complex interactions with the -index option if used on nested lists. Implementing -command is trivial, just copy the code from lsort. It would have fit in quite well for TIP #127, but i didn't see it requested here and no comment was added to the TIP (or mailed to me).
kieranelbyplain2008-08-29 23:36:24
Logged In: YES
user_id=99072
Originator: NO
I've often thought the ability to directly sort a
name-value style of list would be rather useful,
and fancied some exercise in Tcl internals, so I've
created patch 2082681 which adds a "-group" option to lsort:
https://sourceforge.net/tracker/?func=detail&aid=2082681&group_id=10894&atid=310894
When using -group in conjunction with the multiple index
form of -index, it seemed to make most sense to have
-group consume the first index given to -index, and
use that as the offset within each group.
e.g.
% lsort -group 3 -index {0 1} \
{{Bob Smith} 25 Audi {Jane Doe} 40 Ford}
{{Jane Doe} 40 Ford {Bob Smith} 25 Audi}
(since Smith is index 1 of element 0 of the first group of 3,
and it sorts after Doe in the corresponding position in the
2nd group of 3).
I might get round to a patch for lsearch and a TIP at some
point ...
dkf Closed ticket [747083ffff].
[History diff]2008-09-29 15:51:20
dkfplain2008-11-02 18:33:33
data_type - 210894
dkfplain2009-01-30 20:49:11
allow_comments - 1
dkfplain2009-07-29 19:53:42
IP - Comment Removed: 130.88.1.31
Log in (anonymous is fine) to add a comment.