Hi All,
Is it possible to asertain the array index of an htable entry based on its value?
For example, say I have an htable called foo with the following entries:
Entry:: 11 testing[0]:: hello-2 testing[1]:: 1 testing::size:: 2
is it possible to:
[a] extract the array index based on a regex of the value, for example, something like value count: shtcv(foo=>hello-*) [b] if [a] is possible, how would I extract that value (from the associated array index returned in [a] above) from the htable using sht()?
Is the above possible, or am I using the wrong tool for the job?
I did have a look at the htable module docs, but i didnt see anything that stood out to me showing that i could achieve the above. I saw an shtval exported function, but i dont see it documented in the pseudo-var wiki page. I then tried it in the routing script but got an error message to the affect that it couldnt find the PV. I assume its not exported.
All comments welcome and appreciated?
Thanks
I guess the first question would be: why would you want to? Constructs like hash tables and other data structures are usually meant to be used in a high-level way, their inner workings opaque from the user. That tends to be true in general-purpose programming runtimes, as well. What are you trying to achieve?
I was looking to implement a hash table to select a particular dispatcher destination set based on the sip request method. I was hoping to achieve it by using an array in the hash table for a particular domain. so for example have a htable as follows:
domain[0]:: REGISTER-1 domain[1]:: INVITE-2 domain[2]:: 3
where I could then lookup using $rm-* and use transforms to extract the "1" or "2" which would then match up to a setid in the dispatcher table that I could select against, if no match then select the "catch-all" set which would associate with domain[2] above.
Is this achievable with htable or am I using the wrong tool for the job?
I guess another approach would be to hardcode a switch statement relating to the sip request method and use a separate htable for each request type.
Thoughts/comments are appreciated.
On 28/02/12 16:09, Alex Balashov wrote:
I guess the first question would be: why would you want to? Constructs like hash tables and other data structures are usually meant to be used in a high-level way, their inner workings opaque from the user. That tends to be true in general-purpose programming runtimes, as well. What are you trying to achieve?
I would just throw a serialised string into the hash table as a scalar entry, the components of which are separated by some delimiter, e.g.
REGISTER-1;INVITE-2;3
Then, I'd deserialise it by iterating through it with the {s.select} transform and throw it into an AVP array, e.g.
$(avp(s:route_set)[$avp(s:route_set_idx]) = ...
$avp(s:route_set_idx) = $avp(s:route_set_idx) + 1;
Then, I'd just iterate through it using serial forking.
Thanks Alex, I'll go and do some reading up on avp's :)
On 28/02/12 16:25, Alex Balashov wrote:
I would just throw a serialised string into the hash table as a scalar entry, the components of which are separated by some delimiter, e.g.
REGISTER-1;INVITE-2;3
Then, I'd deserialise it by iterating through it with the {s.select} transform and throw it into an AVP array, e.g.
$(avp(s:route_set)[$avp(s:route_set_idx]) = ...
$avp(s:route_set_idx) = $avp(s:route_set_idx) + 1;
Then, I'd just iterate through it using serial forking.