Hello Juha,
I moved the discussion here, in a separate thread. It seems that what are you looking for is not there ... not implemented. If you have the same key_name with different values in the table, the last value will be the one loaded in memory. You can't have an array of values for the same keys. Also, there's no syntax to access a particular value in an array. Maybe that's why there's no option to provide the value.
Please correct me if I understood correctly what you were looking for.
Regards, Ovidiu Sas
On Thu, Feb 13, 2014 at 10:22 PM, Juha Heinanen jh@tutpro.com wrote:
Ovidiu Sas writes:
I noticed that there is delete rpc command: http://kamailio.org/docs/modules/devel/modules/htable#idp15375232 I haven't checked exactly how it works. Is this something to be enhanced? What's missing right now?
value param is missing, i.e., it is not possible to delete a given key/value pair. i looked at the code, but don't have enough json knowledge to figure out all the parameters.
-- juha
Ovidiu Sas writes:
I moved the discussion here, in a separate thread. It seems that what are you looking for is not there ... not implemented.
yes, that is way is asked about it.
If you have the same key_name with different values in the table, the last value will be the one loaded in memory. You can't have an array of values for the same keys.
Also, there's no syntax to access a particular value in an array. Maybe that's why there's no option to provide the value.
see this:
o key type - the type of the key
0 - simple key - the key is added as 'key_name'.
1 - array key - the key is added as 'key_name[n]'. n is incremented for each key with this name to build an array in hash table.
for example:
$var(size) = $sht(htable=>$var(key)::size); $var(i) = 0; while ($var(i) < $var(size)) { $var(value) = $sht(htable=>$var(key)[$var(i)]); ...
-- juha
Hello,
On 22/02/14 22:29, Juha Heinanen wrote:
Ovidiu Sas writes:
I moved the discussion here, in a separate thread. It seems that what are you looking for is not there ... not implemented.
yes, that is way is asked about it.
If you have the same key_name with different values in the table, the last value will be the one loaded in memory. You can't have an array of values for the same keys.
Also, there's no syntax to access a particular value in an array. Maybe that's why there's no option to provide the value.
see this:
o key type - the type of the key
0 - simple key - the key is added as 'key_name'. 1 - array key - the key is added as 'key_name[n]'. n is incremented for each key with this name to build an array in hash table.
for clarifications, this is still a single key item in memory, just its format is made 'key_name[n]'. Hash tables by definition work with unique key indexing.
So adding such items in the hash table should be like:
kamctl mi sht_add ht0 'abc[0]' v0 kamctl mi sht_add ht0 'abc[1]' v1 kamctl mi sht_add ht0 'abc::size' 2
Cheers, Daniel
for example:
$var(size) = $sht(htable=>$var(key)::size); $var(i) = 0; while ($var(i) < $var(size)) { $var(value) = $sht(htable=>$var(key)[$var(i)]); ...
-- juha
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
Hello Daniel,
The readme file or the cookboks don't say anything about this. Can you please enhance the readme? - the indexing: key_name[n] - the array size: key_name::size
Question: can the following syntax be used to delete a specific element in an array key? kamcmd htable.get students anna[2] kamcmd htable.get students anna[0]
Regards, Ovidiu Sas
On Mon, Feb 24, 2014 at 2:52 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
Hello,
On 22/02/14 22:29, Juha Heinanen wrote:
Ovidiu Sas writes:
I moved the discussion here, in a separate thread. It seems that what are you looking for is not there ... not implemented.
yes, that is way is asked about it.
If you have the same key_name with different values in the table, the last value will be the one loaded in memory. You can't have an array of values for the same keys.
Also, there's no syntax to access a particular value in an array. Maybe that's why there's no option to provide the value.
see this:
o key type - the type of the key
0 - simple key - the key is added as 'key_name'. 1 - array key - the key is added as 'key_name[n]'. n is incremented for each key with this name to build an array in hash table.
for clarifications, this is still a single key item in memory, just its format is made 'key_name[n]'. Hash tables by definition work with unique key indexing.
So adding such items in the hash table should be like:
kamctl mi sht_add ht0 'abc[0]' v0 kamctl mi sht_add ht0 'abc[1]' v1 kamctl mi sht_add ht0 'abc::size' 2
Cheers, Daniel
for example:
$var(size) = $sht(htable=>$var(key)::size); $var(i) = 0; while ($var(i) < $var(size)) { $var(value) = $sht(htable=>$var(key)[$var(i)]); ...
-- juha
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
-- Daniel-Constantin Mierla - http://www.asipto.com http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Hello,
iirc, the overview says something about this not-real-array emulation.
The size suffix (::size) is actually a module parameter, it is not something embedded.
So, everything here is more a conceptual approach, could have been very easy something different instead of [ ] to build keys based on an incremented value.
Again, what so ever you have as 'xyz[n]' is just seen as a string by htable module, it is effectively the key in the hash table, you can add, remove, get, etc..
Cheers, Daniel
On 24/02/14 21:40, Ovidiu Sas wrote:
Hello Daniel,
The readme file or the cookboks don't say anything about this. Can you please enhance the readme?
- the indexing: key_name[n]
- the array size: key_name::size
Question: can the following syntax be used to delete a specific element in an array key? kamcmd htable.get students anna[2] kamcmd htable.get students anna[0]
Regards, Ovidiu Sas
On Mon, Feb 24, 2014 at 2:52 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
Hello,
On 22/02/14 22:29, Juha Heinanen wrote:
Ovidiu Sas writes:
I moved the discussion here, in a separate thread. It seems that what are you looking for is not there ... not implemented.
yes, that is way is asked about it.
If you have the same key_name with different values in the table, the last value will be the one loaded in memory. You can't have an array of values for the same keys.
Also, there's no syntax to access a particular value in an array. Maybe that's why there's no option to provide the value.
see this:
o key type - the type of the key
0 - simple key - the key is added as 'key_name'. 1 - array key - the key is added as 'key_name[n]'. n is incremented for each key with this name to build an array in hash table.
for clarifications, this is still a single key item in memory, just its format is made 'key_name[n]'. Hash tables by definition work with unique key indexing.
So adding such items in the hash table should be like:
kamctl mi sht_add ht0 'abc[0]' v0 kamctl mi sht_add ht0 'abc[1]' v1 kamctl mi sht_add ht0 'abc::size' 2
Cheers, Daniel
for example:
$var(size) = $sht(htable=>$var(key)::size); $var(i) = 0; while ($var(i) < $var(size)) { $var(value) = $sht(htable=>$var(key)[$var(i)]); ...
-- juha
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
-- Daniel-Constantin Mierla - http://www.asipto.com http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Yeah, I started to re-read the module, and yes, something is there, but not easy to understand on a first read. Maybe we need to enhance the readme with a small example :)
Let's say, we have table 'test' with an array key with the following values: key[0] with val 'zero' key[1] with val 'one' key[2] with val 'two' and key::size set to 3
If we delete key[1], the we are left with: key[0] with val 'zero' key[2] with val 'two' and key::size set to 2
Now if we add a new key like this: kamcmd htable.sets test key three
What will be the new key set? key[0] with val 'zero' key[2] with val 'two' key[3] with val 'three' and key::size set to 3
Is this correct?
Thanks, Ovidiu
On Mon, Feb 24, 2014 at 3:49 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
Hello,
iirc, the overview says something about this not-real-array emulation.
The size suffix (::size) is actually a module parameter, it is not something embedded.
So, everything here is more a conceptual approach, could have been very easy something different instead of [ ] to build keys based on an incremented value.
Again, what so ever you have as 'xyz[n]' is just seen as a string by htable module, it is effectively the key in the hash table, you can add, remove, get, etc..
Cheers, Daniel
On 24/02/14 21:40, Ovidiu Sas wrote:
Hello Daniel,
The readme file or the cookboks don't say anything about this. Can you please enhance the readme?
- the indexing: key_name[n]
- the array size: key_name::size
Question: can the following syntax be used to delete a specific element in an array key? kamcmd htable.get students anna[2] kamcmd htable.get students anna[0]
Regards, Ovidiu Sas
On Mon, Feb 24, 2014 at 2:52 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
Hello,
On 22/02/14 22:29, Juha Heinanen wrote:
Ovidiu Sas writes:
I moved the discussion here, in a separate thread. It seems that what are you looking for is not there ... not implemented.
yes, that is way is asked about it.
If you have the same key_name with different values in the table, the last value will be the one loaded in memory. You can't have an array of values for the same keys.
Also, there's no syntax to access a particular value in an array. Maybe that's why there's no option to provide the value.
see this:
o key type - the type of the key
0 - simple key - the key is added as 'key_name'. 1 - array key - the key is added as 'key_name[n]'. n is
incremented for each key with this name to build an array in hash table.
for clarifications, this is still a single key item in memory, just its format is made 'key_name[n]'. Hash tables by definition work with unique key indexing.
So adding such items in the hash table should be like:
kamctl mi sht_add ht0 'abc[0]' v0 kamctl mi sht_add ht0 'abc[1]' v1 kamctl mi sht_add ht0 'abc::size' 2
Cheers, Daniel
for example:
$var(size) = $sht(htable=>$var(key)::size); $var(i) = 0; while ($var(i) < $var(size)) { $var(value) = $sht(htable=>$var(key)[$var(i)]); ...
-- juha
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
-- Daniel-Constantin Mierla - http://www.asipto.com http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
-- Daniel-Constantin Mierla - http://www.asipto.com http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
On 24/02/14 21:58, Ovidiu Sas wrote:
Yeah, I started to re-read the module, and yes, something is there, but not easy to understand on a first read. Maybe we need to enhance the readme with a small example :)
Let's say, we have table 'test' with an array key with the following values: key[0] with val 'zero' key[1] with val 'one' key[2] with val 'two' and key::size set to 3
If we delete key[1], the we are left with: key[0] with val 'zero' key[2] with val 'two' and key::size set to 2
Now if we add a new key like this: kamcmd htable.sets test key three
What will be the new key set? key[0] with val 'zero' key[2] with val 'two' key[3] with val 'three' and key::size set to 3
Is this correct?
No. The 'so-called-array-here' is built only at the time of loading from db -- it is practically constructing a new key from the value loaded from the database concatenated with '[', plus the number of items with same db key value that were added before, plus ']'.
Then, at runtime, if you remove/add items with x[N] format, you need to adjust the x::size. The module doesn't do it. If anyone is willing to add a patch, all is welcome.
Cheers, Daniel
Thanks, Ovidiu
On Mon, Feb 24, 2014 at 3:49 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
Hello,
iirc, the overview says something about this not-real-array emulation.
The size suffix (::size) is actually a module parameter, it is not something embedded.
So, everything here is more a conceptual approach, could have been very easy something different instead of [ ] to build keys based on an incremented value.
Again, what so ever you have as 'xyz[n]' is just seen as a string by htable module, it is effectively the key in the hash table, you can add, remove, get, etc..
Cheers, Daniel
On 24/02/14 21:40, Ovidiu Sas wrote:
Hello Daniel,
The readme file or the cookboks don't say anything about this. Can you please enhance the readme?
- the indexing: key_name[n]
- the array size: key_name::size
Question: can the following syntax be used to delete a specific element in an array key? kamcmd htable.get students anna[2] kamcmd htable.get students anna[0]
Regards, Ovidiu Sas
On Mon, Feb 24, 2014 at 2:52 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
Hello,
On 22/02/14 22:29, Juha Heinanen wrote:
Ovidiu Sas writes:
I moved the discussion here, in a separate thread. It seems that what are you looking for is not there ... not implemented.
yes, that is way is asked about it.
If you have the same key_name with different values in the table, the last value will be the one loaded in memory. You can't have an array of values for the same keys.
Also, there's no syntax to access a particular value in an array. Maybe that's why there's no option to provide the value.
see this:
o key type - the type of the key
0 - simple key - the key is added as 'key_name'. 1 - array key - the key is added as 'key_name[n]'. n is
incremented for each key with this name to build an array in hash table.
for clarifications, this is still a single key item in memory, just its format is made 'key_name[n]'. Hash tables by definition work with unique key indexing.
So adding such items in the hash table should be like:
kamctl mi sht_add ht0 'abc[0]' v0 kamctl mi sht_add ht0 'abc[1]' v1 kamctl mi sht_add ht0 'abc::size' 2
Cheers, Daniel
for example:
$var(size) = $sht(htable=>$var(key)::size); $var(i) = 0; while ($var(i) < $var(size)) { $var(value) = $sht(htable=>$var(key)[$var(i)]); ... -- juha
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
-- Daniel-Constantin Mierla - http://www.asipto.com http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
-- Daniel-Constantin Mierla - http://www.asipto.com http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Thanks for clarifying this. I will update the README.
Thanks, Ovidiu
On Mon, Feb 24, 2014 at 4:04 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
On 24/02/14 21:58, Ovidiu Sas wrote:
Yeah, I started to re-read the module, and yes, something is there, but not easy to understand on a first read. Maybe we need to enhance the readme with a small example :)
Let's say, we have table 'test' with an array key with the following values: key[0] with val 'zero' key[1] with val 'one' key[2] with val 'two' and key::size set to 3
If we delete key[1], the we are left with: key[0] with val 'zero' key[2] with val 'two' and key::size set to 2
Now if we add a new key like this: kamcmd htable.sets test key three
What will be the new key set? key[0] with val 'zero' key[2] with val 'two' key[3] with val 'three' and key::size set to 3
Is this correct?
No. The 'so-called-array-here' is built only at the time of loading from db -- it is practically constructing a new key from the value loaded from the database concatenated with '[', plus the number of items with same db key value that were added before, plus ']'.
Then, at runtime, if you remove/add items with x[N] format, you need to adjust the x::size. The module doesn't do it. If anyone is willing to add a patch, all is welcome.
Cheers, Daniel
Thanks, Ovidiu
On Mon, Feb 24, 2014 at 3:49 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
Hello,
iirc, the overview says something about this not-real-array emulation.
The size suffix (::size) is actually a module parameter, it is not something embedded.
So, everything here is more a conceptual approach, could have been very easy something different instead of [ ] to build keys based on an incremented value.
Again, what so ever you have as 'xyz[n]' is just seen as a string by htable module, it is effectively the key in the hash table, you can add, remove, get, etc..
Cheers, Daniel
On 24/02/14 21:40, Ovidiu Sas wrote:
Hello Daniel,
The readme file or the cookboks don't say anything about this. Can you please enhance the readme?
- the indexing: key_name[n]
- the array size: key_name::size
Question: can the following syntax be used to delete a specific element in an array key? kamcmd htable.get students anna[2] kamcmd htable.get students anna[0]
Regards, Ovidiu Sas
On Mon, Feb 24, 2014 at 2:52 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
Hello,
On 22/02/14 22:29, Juha Heinanen wrote:
Ovidiu Sas writes:
> I moved the discussion here, in a separate thread. > It seems that what are you looking for is not there ... not > implemented.
yes, that is way is asked about it.
> If you have the same key_name with different values in the table, the > last value will be the one loaded in memory. > You can't have an array of values for the same keys.
> Also, there's no syntax to access a particular value in an array. > Maybe that's why there's no option to provide the value.
see this:
o key type - the type of the key
0 - simple key - the key is added as 'key_name'. 1 - array key - the key is added as 'key_name[n]'. n is
incremented for each key with this name to build an array in hash table.
for clarifications, this is still a single key item in memory, just its format is made 'key_name[n]'. Hash tables by definition work with unique key indexing.
So adding such items in the hash table should be like:
kamctl mi sht_add ht0 'abc[0]' v0 kamctl mi sht_add ht0 'abc[1]' v1 kamctl mi sht_add ht0 'abc::size' 2
Cheers, Daniel
for example:
$var(size) = $sht(htable=>$var(key)::size); $var(i) = 0; while ($var(i) < $var(size)) { $var(value) = $sht(htable=>$var(key)[$var(i)]); ... -- juha
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
-- Daniel-Constantin Mierla - http://www.asipto.com http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
-- Daniel-Constantin Mierla - http://www.asipto.com http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
-- Daniel-Constantin Mierla - http://www.asipto.com http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Daniel-Constantin Mierla writes:
Then, at runtime, if you remove/add items with x[N] format, you need to adjust the x::size. The module doesn't do it. If anyone is willing to add a patch, all is welcome.
when you add key/value pair , adjusting key:size is enough, but if you delete a key/value pair, you must also fill the possible hole with some other value.
-- juha
Daniel-Constantin Mierla writes:
Again, what so ever you have as 'xyz[n]' is just seen as a string by htable module, it is effectively the key in the hash table, you can add, remove, get, etc..
yes, i was offline a few days and read the code. there is no real array in hash table, but just separate entries key[x] and key::size that tells how many.
adding a new one could be code by setting key[key::size] and then incrementing key::size. deleting an entry would be more difficult, because the hole would need to be filled with another element.
one way to improve the situation could be introduction of a new key type, e.g., dictionary. which allows the same key to have multiple values. the values would then be linked from the key entry in the hash table and there would be first(key) and next(key) functions to access the values and delete(key) and delete(key, value) functions.
-- juha
Juha,
Based on how htable works now, a specific pseudoarray entry can be deleted by specifying it's position: kamcmd htable.delete H_TABLE H_KEY[INDEX] I tested it and it works ok.
-ovidiu
On Sat, Feb 22, 2014 at 4:29 PM, Juha Heinanen jh@tutpro.com wrote:
Ovidiu Sas writes:
I moved the discussion here, in a separate thread. It seems that what are you looking for is not there ... not implemented.
yes, that is way is asked about it.
If you have the same key_name with different values in the table, the last value will be the one loaded in memory. You can't have an array of values for the same keys.
Also, there's no syntax to access a particular value in an array. Maybe that's why there's no option to provide the value.
see this:
o key type - the type of the key
0 - simple key - the key is added as 'key_name'. 1 - array key - the key is added as 'key_name[n]'. n is incremented for each key with this name to build an array in hash table.
for example:
$var(size) = $sht(htable=>$var(key)::size); $var(i) = 0; while ($var(i) < $var(size)) { $var(value) = $sht(htable=>$var(key)[$var(i)]); ...
-- juha
Ovidiu Sas writes:
Based on how htable works now, a specific pseudoarray entry can be deleted by specifying it's position: kamcmd htable.delete H_TABLE H_KEY[INDEX] I tested it and it works ok.
yes, but it breaks the while loop example unless you also fill the hole and decrement key::size.
-- juha
As it is implemented right now, there's no hole, because we don't have a true array, just keys with a shared prefix. I guess the term array that is used right now is not right (it sets certain expectations). Maybe map is a better term.
Anyway, I updated the documentation to reflect the current code. And the loop example that you provided is what one would expect based on the 'array' term. If we would use 'map' term, maybe the confusion could be avoided.
Also, it is true that there's no bulletproof way to iterate through all value/pairs of a given key after performing operations on an 'array' key. It seems that this is what's really missing here. Although, a well crafted script could handle this.
Regards, Ovidiu Sas
On Tue, Feb 25, 2014 at 2:47 PM, Juha Heinanen jh@tutpro.com wrote:
Ovidiu Sas writes:
Based on how htable works now, a specific pseudoarray entry can be deleted by specifying it's position: kamcmd htable.delete H_TABLE H_KEY[INDEX] I tested it and it works ok.
yes, but it breaks the while loop example unless you also fill the hole and decrement key::size.
-- juha