Hi,
one of my TCL projects using an ARRAY to match a source-key to a target, example:
array set map_M2S_local {
ME_NB1_MK_BOL Byte
ME_NI1_MK_BYT SByte
ME_NI2_MK_SRT Int16
ME_NI4_MK_INT Int32
ME_NI8_MK_WID Int64
ME_NF4_MK_FLT Single
ME_NF8_MK_DBL Double
ME_NI4_MK_DBG Int32
ME_NI4_MQ_HDL Int32
ME_NI4_MK_NUM Int32
ME_NI4_MQ_SLAVE_ID Int32
ME_NI4_MQ_SOCK_HDL Int32
ME_NI4_MQ_LTR Int32
ME_NI4_MQ_ROU Int32
ME_PVO_MK_PTR IntPtr
ME_PBI_MK_BIN IntPtr
ME_PBN_MK_BINN IntPtr
ME_PSN_MQ_TOKEN IntPtr
ME_PSS_MK_STR IntPtr
ME_PSN_MK_STRN IntPtr
ME_PFS_MK_FST IntPtr
ME_PLI_MK_LST IntPtr
ME_PVO_IDNT IntPtr
ME_REF_MkBinaryR IntPtr
...
}
as you see there are many items which hast *multiple* keys BUT a *unique* target.
example ME_NI4_* is always mapping to *Int32*
Problem: for a *new* key this array have *always* been updated even if the *new* follow
the already known ME_NI4_* → Int32 syntax.
NEW
It would be nice to have an ARRAY which is able to use a key with pattern or regexp matching
array set ?-glob? map_M2S_local {
ME_NB1_MK_BOL Byte
ME_NI1_MK_BYT SByte
ME_NI2_MK_SRT Int16
ME_NI4_MK_INT Int32
ME_NI8_MK_WID Int64
ME_NF4_MK_FLT Single
ME_NF8_MK_DBL Double
ME_NI4_* Int32
ME_P* IntPtr
ME_REF_MkBinaryR IntPtr
...
}
and '$map_M2S_local(ME_NI4_something)' would return *Int32*
I know that it is possible to implement this as *switch* with a lot of "writing" in a 'proc' as wrapper
mfg AO
Hi,
one of my TCL projects using an ARRAY to match a source-key to a
target, example:
array set map_M2S_local {
ME_NB1_MK_BOL Byte
ME_NI1_MK_BYT SByte
ME_NI2_MK_SRT Int16
ME_NI4_MK_INT Int32
ME_NI8_MK_WID Int64
ME_NF4_MK_FLT Single
ME_NF8_MK_DBL Double
ME_NI4_MK_DBG Int32
ME_NI4_MQ_HDL Int32
ME_NI4_MK_NUM Int32
ME_NI4_MQ_SLAVE_ID Int32
ME_NI4_MQ_SOCK_HDL Int32
ME_NI4_MQ_LTR Int32
ME_NI4_MQ_ROU Int32
ME_PVO_MK_PTR IntPtr
ME_PBI_MK_BIN IntPtr
ME_PBN_MK_BINN IntPtr
ME_PSN_MQ_TOKEN IntPtr
ME_PSS_MK_STR IntPtr
ME_PSN_MK_STRN IntPtr
ME_PFS_MK_FST IntPtr
ME_PLI_MK_LST IntPtr
ME_PVO_IDNT IntPtr
ME_REF_MkBinaryR IntPtr
...
}
as you see there are many items which hast *multiple* keys BUT a
*unique* target.
example ME_NI4_* is always mapping to *Int32*
Problem: for a *new* key this array have *always* been updated even if
the *new* follow
the already known ME_NI4_* → Int32 syntax.
NEW
It would be nice to have an ARRAY which is able to use a key with
pattern or regexp matching
array set ?-glob? map_M2S_local {
ME_NB1_MK_BOL Byte
ME_NI1_MK_BYT SByte
ME_NI2_MK_SRT Int16
ME_NI4_MK_INT Int32
ME_NI8_MK_WID Int64
ME_NF4_MK_FLT Single
ME_NF8_MK_DBL Double
ME_NI4_* Int32
ME_P* IntPtr
ME_REF_MkBinaryR IntPtr
...
}
and '$map_M2S_local(ME_NI4_something)' would return *Int32*
I know that it is possible to implement this as *switch* with a lot of "writing" in a 'proc' as wrapper
On 3/25/23 14:45, aotto1968 wrote:
Hi,
Read the man/doc page for the array command, pay particular attention to the name subcommand.
Am 26.03.23 um 08:49 schrieb aotto1968:
On 26.03.23 04:00, Gerald Lester wrote:
It is clear that the pattern is the KEY and not the LOOKUP.
array set test {
key??next* myValueToSearchFor
}
set test(key12nextSomething) -> myValueToSearchFor
I already know that it is possible to transform an array into a list (array names ..., array get ...) and process
each entry (one by one) BUT you loose all speed advantages of an array. just assume that the array has 1 million entries
and you will understand that loop over oneBYone is not the best choice. >
I know it is NOT trivial to use a PATTERN as key in an array
And how would you think it is possible to implement such a feature, if not by looping over the entries one by one? It would help
of course when the lookup goes to the C level instead of a Tcl level loop, but you would still spend most of the time matching
the patterns one by one.
There is one (half-theoretical) other way to get faster lookups, that is by transforming the patterns into a giant state machine
where the end points correspond to the patterns. Basically this is what "lex" does. As you can imagine, transforming 1 million
patterns into a single state machine is going to take a very long time and consume lots of memory. It can be done once for a
static array and then applied multiple times, but it is not suitable for a dynamic construct like an array.
Christian
On 26.03.23 04:00, Gerald Lester wrote:
It is clear that the pattern is the KEY and not the LOOKUP.
array set test {
key??next* myValueToSearchFor
}
set test(key12nextSomething) -> myValueToSearchFor
I already know that it is possible to transform an array into a list
(array names ..., array get ...) and process
each entry (one by one) BUT you loose all speed advantages of an array.
just assume that the array has 1 million entries
and you will understand that loop over oneBYone is not the best choice. >
I know it is NOT trivial to use a PATTERN as key in an array
On 26.03.23 04:00, Gerald Lester wrote:
Read the man/doc page for the array command, pay particular
attention to the name subcommand.
It is clear that the pattern is the KEY and not the LOOKUP.
array set test {
key??next* myValueToSearchFor
}
set test(key12nextSomething) -> myValueToSearchFor
I already know that it is possible to transform an array into a list
(array names ..., array get ...) and process each entry (one by one)
BUT you loose all speed advantages of an array. just assume that the
array has 1 million entries and you will understand that loop over
oneBYone is not the best choice.
I know it is NOT trivial to use a PATTERN as key in an array
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 152:05:26 |
| Calls: | 12,091 |
| Calls today: | 4 |
| Files: | 15,000 |
| Messages: | 6,517,631 |