Eric Chamberlain
2008-Sep-14 00:40 UTC
[asterisk-users] Can someone give a plain english explanation of the HASH function?
Can someone explain what the HASH function does and how to use it? -= Info about function 'HASH' =- [Syntax] HASH(hashname[,hashkey]) [Synopsis] Implementation of a dialplan associative array [Description] In two argument mode, gets and sets values to corresponding keys within a named associative array. The single-argument mode will only work when assigned to from a function defined by func_odbc.so. -- Eric Chamberlain Founder RF.com http://RF.com/
Alex Balashov
2008-Sep-14 00:47 UTC
[asterisk-users] Can someone give a plain english explanation of the HASH function?
There is no "plain English" explanation that is not made with reference to the concept of a hash, which is an algorithmic and programmatic technique. The HASH() function is designed for people that understand what hashing is and need to make use of it. So, the answer is, "it provides a hashing mechanism to the user." The simplest way to discover what hashing is would be to educate yourself about hash tables and associative arrays (which provide high-level, usually type-safe syntactical bindings around the use of hash tables) in other contexts, after which it should be clear. Soliciting any sort of Asterisk-specific explanation is going to give you an incomplete, oversimplified, and/or reductionist viewpoint. I would start here: http://en.wikipedia.org/wiki/Hash_function Cheers, -- Alex Eric Chamberlain wrote:> Can someone explain what the HASH function does and how to use it? > > > -= Info about function 'HASH' =- > > [Syntax] > HASH(hashname[,hashkey]) > > [Synopsis] > Implementation of a dialplan associative array > > [Description] > In two argument mode, gets and sets values to corresponding keys > within a named > associative array. The single-argument mode will only work when > assigned to from > a function defined by func_odbc.so.-- Alex Balashov Evariste Systems Web : http://www.evaristesys.com/ Tel : (+1) (678) 954-0670 Direct : (+1) (678) 954-0671 Mobile : (+1) (706) 338-8599
Tilghman Lesher
2008-Sep-14 02:08 UTC
[asterisk-users] Can someone give a plain english explanation of the HASH function?
On Saturday 13 September 2008 19:40:45 Eric Chamberlain wrote:> Can someone explain what the HASH function does and how to use it?func_odbc.conf: [FOO] dsn=mysql readsql=SELECT * FROM foo WHERE somefield='${SQL_ESC(${ARG1})}' extensions.conf: Set(HASH(foo)=${ODBC_FOO(${bar})}) Now you can reference ${HASH(foo,somefield)} or ${HASH(foo,someotherfield)}. You can even add things to the HASH foo with: Set(HASH(foo,notinthetable)=baz). Basically, it's a way to retrieve multiple values from a database without using ARRAY() to enumerate each field, but also without polluting the variable namespace, which could cause unexpected behavior, such as when somebody adds a field to a database table whose name happens to coincide with an existing variable. In short, it's a way to be able to use a 'SELECT *' query which doesn't break when somebody adds columns to a table. -- Tilghman
MAGUIRE MATTHEW
2008-Sep-15 19:21 UTC
[asterisk-users] Can someone give a plain english explanation of the HASH function?
> There is no "plain English" explanation that is not made withreference> to the concept of a hash, which is an algorithmic and programmatic > technique. The HASH() function is designed for people that understand > what hashing is and need to make use of it. > ... > I would start here: > > http://en.wikipedia.org/wiki/Hash_functionThat is a good detailed article, but for a higher level overview of what the HASH() function is meant to achieve, I would recommend the following article: http://en.wikipedia.org/wiki/Associative_array (A hash table is a common way to implement an associate array, but the article on hash tables goes into a lot of implementation detail that is not really necessary for understanding how to use the asterisk HASH() function) Others have already listed some good examples of why you might want to use such a feature in your dialplan. -Matt.