The [lsort] command has a -dictionary option to sort list entries in
dictionary order, i.e.,
embedded numbers are sorted as numbers rather than as individual
characters. Is the
underlying comparison available anywhere as a separate command?
There's no
[string compare -dictionary] command, although that's an obvious
enhancement
given [lsort -dictionary].
I mean, I could compare two strings by putting them in a list, sorting
the list
with -dictionary, and seeing which comes first...but that seems a
little inefficient
somehow. Anybody got anything better?
|
|
0
|
|
|
|
Reply
|
will181 (157)
|
11/17/2010 8:13:53 PM |
|
On Nov 17, 9:13=A0pm, Will Duquette <w...@wjduquette.com> wrote:
> The [lsort] command has a -dictionary option to sort list entries in
> dictionary order, i.e.,
> embedded numbers are sorted as numbers rather than as individual
> characters. =A0Is the
> underlying comparison available anywhere as a separate command?
> There's no
> [string compare -dictionary] command, although that's an obvious
> enhancement
> given [lsort -dictionary].
>
> I mean, I could compare two strings by putting them in a list, sorting
> the list
> with -dictionary, and seeing which comes first...but that seems a
> little inefficient
> somehow. =A0Anybody got anything better?
Indeed, DictionaryCompare() is static in tclCmdIL.c, and is only used
by [lsort] and [lsearch].
TIPworthy :)
-Alex
|
|
0
|
|
|
|
Reply
|
Alexandre
|
11/17/2010 9:40:32 PM
|
|
On 2010-11-17, Will Duquette wrote:
>
> The [lsort] command has a -dictionary option to sort list entries in
> dictionary order, i.e., embedded numbers are sorted as numbers rather
> than as individual characters. Is the underlying comparison available
> anywhere as a separate command?
As far as I know, no.
It probably should be.
This is what I've been using:
| proc dictionary_compare {a b} {
| lindex [lsort -dictionary -index 0 [list [list $a -1] [list $b 1]]] 0 1
| }
which is bloody horrible, but it's the shortest path between
"what you want" and "what you've got" that I've found so far.
--JE
|
|
0
|
|
|
|
Reply
|
Joe
|
11/17/2010 9:59:41 PM
|
|
On Nov 17, 10:59=A0pm, Joe English <jengl...@flightlab.com> wrote:
> On 2010-11-17, Will Duquette wrote:
>
>
>
> > The [lsort] command has a -dictionary option to sort list entries in
> > dictionary order, i.e., embedded numbers are sorted as numbers rather
> > than as individual characters. =A0Is the underlying comparison availabl=
e
> > anywhere as a separate command?
>
> As far as I know, no.
>
> It probably should be.
>
> This is what I've been using:
>
> | proc dictionary_compare {a b} {
> | =A0 =A0lindex [lsort -dictionary -index 0 [list [list $a -1] [list $b 1=
]]] 0 1
> | }
>
> which is bloody horrible, but it's the shortest path between
> "what you want" and "what you've got" that I've found so far.
Funnily, in my tests the above is slightly slower than
proc dictionary_compare {a b} {
expr {[string equal $a [lindex [lsort -dictionary [list $a $b]]
0]]?-1:1}
}
Possibly because, for the small strings I used, the extra [string
equal] is dominated by the list nesting overhead.
-Alex
|
|
0
|
|
|
|
Reply
|
Alexandre
|
11/17/2010 10:10:05 PM
|
|
On Nov 17, 2:10=A0pm, Alexandre Ferrieux <alexandre.ferri...@gmail.com>
wrote:
> On Nov 17, 10:59=A0pm, Joe English <jengl...@flightlab.com> wrote:
>
>
>
>
>
> > On 2010-11-17, Will Duquette wrote:
>
> > > The [lsort] command has a -dictionary option to sort list entries in
> > > dictionary order, i.e., embedded numbers are sorted as numbers rather
> > > than as individual characters. =A0Is the underlying comparison availa=
ble
> > > anywhere as a separate command?
>
> > As far as I know, no.
>
> > It probably should be.
>
> > This is what I've been using:
>
> > | proc dictionary_compare {a b} {
> > | =A0 =A0lindex [lsort -dictionary -index 0 [list [list $a -1] [list $b=
1]]] 0 1
> > | }
>
> > which is bloody horrible, but it's the shortest path between
> > "what you want" and "what you've got" that I've found so far.
>
> Funnily, in my tests the above is slightly slower than
>
> =A0 =A0proc dictionary_compare {a b} {
> =A0 =A0 expr {[string equal $a [lindex [lsort -dictionary [list $a $b]]
> 0]]?-1:1}
> =A0 =A0}
>
> Possibly because, for the small strings I used, the extra [string
> equal] is dominated by the list nesting overhead.
>
> -Alex
Thanks much, both. I'll give 'em both a try.
|
|
0
|
|
|
|
Reply
|
Will
|
11/17/2010 11:11:12 PM
|
|
Hi,
so there is already an isolated C function in tcl for comparing
strings in dictionary mode?
Wonderful!
So lets TIP!
Regards,
Martin
On 17 Nov., 22:40, Alexandre Ferrieux <alexandre.ferri...@gmail.com>
wrote:
> On Nov 17, 9:13=A0pm, Will Duquette <w...@wjduquette.com> wrote:
>
> > The [lsort] command has a -dictionary option to sort list entries in
> > dictionary order, i.e.,
> > embedded numbers are sorted as numbers rather than as individual
> > characters. =A0Is the
> > underlying comparison available anywhere as a separate command?
> > There's no
> > [string compare -dictionary] command, although that's an obvious
> > enhancement
> > given [lsort -dictionary].
>
> > I mean, I could compare two strings by putting them in a list, sorting
> > the list
> > with -dictionary, and seeing which comes first...but that seems a
> > little inefficient
> > somehow. =A0Anybody got anything better?
>
> Indeed, DictionaryCompare() is static in tclCmdIL.c, and is only used
> by [lsort] and [lsearch].
>
> TIPworthy :)
>
> -Alex
|
|
0
|
|
|
|
Reply
|
MartinLemburg
|
11/18/2010 9:16:21 AM
|
|
|
5 Replies
412 Views
(page loaded in 0.796 seconds)
Similiar Articles: Hardware decoding of adaptive dictionary based techniques - - comp ...string compare -dictionary? - comp.lang.tcl Matching Partial Data - comp.databases.ms-access... it only check the first 3 characters of each to compare. ... Compare numbers - comp.soft-sys.matlabstring compare -dictionary? - comp.lang.tcl The [lsort] command has a -dictionary option to sort list entries in dictionary order, i.e., embedded numbers are sorted as ... power scheme from /proc/cpuinfo: What does index 8 mean? - comp.os ...string compare -dictionary? - comp.lang.tcl I mean, I could compare two strings by putting them ... This is what I've been using: | proc dictionary_compare {a b ... Use Kolmogorov Test - comp.soft-sys.matlabstring compare -dictionary? - comp.lang.tcl > > Funnily, in my tests the above is slightly slower than > > =A0 =A0proc ... The Kolmogorov complexity of a string is defined ... Enform query - Count, sort with partial string - comp.sys.tandem ...The report job might use DDL to open the production dictionary, use the DDL ... tables - comp.lang.java.help ..... need to use getString and compare the content by String ... NonStop SOAP server performance tuning - comp.sys.tandem ...However when you compare it with a non Tandem platform, most ... > > The solution was to write a program which reads DDL dictionary and > > converts the DDL into a big string ... class definition containing member of own type - comp.lang.c++ ...- Imagine XString as a class with std::string _container ... std::map MyString, MyString > comparison operator? - comp ... class - definition of class by the Free Online Dictionary ... DCPS v2.7 problem with HP P2055dn printer - comp.os.vms... of a MediaType entry in the InputAttributes dictionary a ... to force that type to be used, since no comparison could ... late that the printer uses a slightly different string. RESIGNATION OF STEVE JOBS!! - comp.sys.mac.systemRemove the string "HatesSpam" from this email address ... Today's Mac bears little resemblance to OS9, in comparison ... in order to look up a word in Oxford English Dictionary ... top 10 uses for random data compression?? anyone? - comp ...Don't try to attribute a string! Hardly any top ... whenever Tariq generates the applicable comparison very ... matter how than comprise with Murad's broken dictionary. c# - Compare 2 List > - Stack OverflowI have a function which returns a List<Dictionary<string, object>> where object is a standard type (string, int, etc). I need to take a second List<Dictionary<string ... Linchi Shea : String comparison: binary vs. dictionaryIt is well known that you get better performance if you compare two strings in a binary collation than in a dictionary collation. But is the performance difference ... 7/23/2012 7:42:54 PM
|