[SparForte][Banner]
[Top Main Menu] Intro | Tutorials | Reference | Packages | Examples | Contributors   [Back Page]      [Next Page]  

Dynamic Hash Tables Package

The SparForte built-in dynamic_hash_tables package contains subprograms to create and manage simple hash tables.

Introduced: SparForte 1.5

GCC Ada Equivalent: Gnat.Dynamic_Hash_Tables

A hash table is a lookup table containing key-value pairs. Keys are unique in the table.

This package includes a new type:

  • dynamic_hash_tables.table
=> type url_string is new string
=> dynamic_hash_tables.new_table( urls, url_string )
=> (Assuming urls is a new dynamic_hash_tables.table variable)
=> u : url_string
=> dynamic_hash_tables.get_first( urls, u, eof )
=> (Assuming eof is a new boolean variable)
=> ? eof
true
=> dynamic_hash_tables.set( urls, "google", "http://www.google.com" )
=> dynamic_hash_tables.set( urls, "yahoo", "http://www.yahoo.com" )
=> dynamic_hash_tables.set( urls, "amazon", "http://www.amazon.com" )
=> ? dynamic_hash_tables.has_element( urls, "google" )
true
=> ? dynamic_hash_tables.get( urls, "google" )
http://www.google.com
=> dynamic_hash_tables.get_first( urls, u, eof )
=> ? eof
false
=> ? u
http://www.amazon.com
=> dynamic_hash_tables.get_next( urls, u, eof )
=> ? eof
false
=> ? u
http://www.google.com
=> dynamic_hash_tables.set( urls, "amazon", 12345 )
dynamic_hash_tables.set( urls, "amazon", 12345 );
                                                ^ type universal_numeric is
inherently different from an url_string (an universal_string)

 
Example: Using dynamic_hash_tables to store URL's

dynamic_hash_tables.add( t, k, v )

 

Put value v under key k in the hash table. If the key already exists, do nothing.

Example

dynamic_hash_tables.add( fruit, "apples", 15 );

Parameters

Param Mode Type Default Description
t in out dynamic_hash_tables.table required the table
k in string required the key
v in table value type required the value

Exceptions

An exception is raised if the value is the wrong type
An exception is raised if out of memory

Restrictions

Not allowed with pragma ada_95

See Also

dynamic_hash_tables.set
dynamic_hash_tables.replace

Compare With

Ada: N/A (AdaScript extension)

Implementation Note

This is in accordance with memcached.

dynamic_hash_tables.append( t, k, v )

 

Append string value v to the value under key k in the hash table. If the key does not exist, do nothing.

Example

dynamic_hash_tables.set( fruit_unit, "apples", "bushel" );
doubly_linked_lists.append( fruit_unit, "apples", "s" );

Parameters

Param Mode Type Default Description
t in out dynamic_hash_tables.table required the table
k in string required the key
v in table value type required the string to append

Exceptions

An exception is raised if the value is the wrong type
An exception is raised if out of memory
An exception is raised if the value type is not a string

Restrictions

Not allowed with pragma ada_95

See Also

dynamic_hash_tables.prepend

Compare With

Ada: N/A (AdaScript extension)

Implementation Note

This is in accordance with memcached.

dynamic_hash_tables.decrement( t, k [,n] )

 

Reduce the numeric value under key k in the hash table by one (or n). If the key does not exist, do nothing.

Example

dynamic_hash_tables.decrement( fruit, "apples" );

Parameters

Param Mode Type Default Description
t in out dynamic_hash_tables.table required the table
k in string required the key
n in table value type 1 the amount to decrement

Exceptions

An exception is raised if the value is the wrong type
An exception is raised if out of memory
An exception is raised if the value type is not numeric

Restrictions

Not allowed with pragma ada_95

See Also

dynamic_hash_tables.increment

Compare With

Ada: N/A (AdaScript extension)

Implementation Note

This is in accordance with memcached.

v := dynamic_hash_tables.get( t, k )

 

Get the value under key k in the hash table.

Example

put_line( dynamic_hash_tables.get( fruit, "apples" ) );

Parameters

Param Mode Type Default Description
v return value table value type required the value
t in dynamic_hash_tables.table required the table
k in string required the key

Exceptions

-

See Also

-

Compare With

Ada: Gnat.Dynamic_Hash_Tables.Get

dynamic_hash_tables.get_first( t, v, f )

 

Iterate through the hash table. Return the first value in the table. Order of the values is not predictable.

Example

dynamic_hash_tables.get_first( fruit, first_value, eof );

Parameters

Param Mode Type Default Description
t in out dynamic_hash_tables.table required the table
v in out table value type required the first value
e out boolean required true if the table is empty

Exceptions

An exception is raised if the value is the wrong type

Restrictions

Not allowed with pragma ada_95

See Also

dynamic_hash_tables.get_next

Compare With

Ada: Gnat.Dynamic_Hash_Tables.Get_First

Implementation Note

Ada uses different parameters.

dynamic_hash_tables.get_next( t, v, f )

 

Iterate through the hash table. Return the next value in the table. Order of the values is not predictable. Use get_first to start iterating. If iteration breaks if the table is altered.

Example

dynamic_hash_tables.get_next( fruit, next_value, eof );

Parameters

Param Mode Type Default Description
t in out dynamic_hash_tables.table required the table
v in out table value type required the first value
e out boolean required true if there are no more elements

Exceptions

An exception is raised if the value is the wrong type

Restrictions

Not allowed with pragma ada_95

See Also

dynamic_hash_tables.get_first

Compare With

Ada: Gnat.Dynamic_Hash_Tables.Get_Next

Implementation Note

Ada uses different parameters.

b := dynamic_hash_tables.has_element( t, k )

 

Get the value under key k in the hash table.

Example

if dynamic_hash_tables.has_element( fruit, "apples" ) then ...

Parameters

Param Mode Type Default Description
b return value boolean required true if there is an element
t in dynamic_hash_tables.table required the table
k in string required the key

Exceptions

-

See Also

Ada: N/A (AdaScript extension)

Compare With

Ada: Gnat.Dynamic_Hash_Tables.Get

dynamic_hash_tables.increment( t, k [,n] )

 

Increase the numeric value under key k in the hash table by one (or n). If the key does not exist, do nothing.

Example

dynamic_hash_tables.increment( fruit, "apples" );

Parameters

Param Mode Type Default Description
t in out dynamic_hash_tables.table required the table
k in string required the key
n in table value type 1 the amount to increment

Exceptions

An exception is raised if the value is the wrong type
An exception is raised if out of memory
An exception is raised if the value type is not numeric

Restrictions

Not allowed with pragma ada_95

See Also

dynamic_hash_tables.decrement

Compare With

Ada: N/A (AdaScript extension)

Implementation Note

This is in accordance with memcached.

dynamic_hash_tables.new_table( t, y )

 

Initialize a new hash table, assigning the type for the values in the table. The value type must be a scalar type, and it may be a universal type.

Example

dynamic_hash_tables.new_table( fruit, natural );

Parameters

Param Mode Type Default Description
t out dynamic_hash_tables.table required the table to initialize
y in the value type required the type of values

Exceptions

An exception is raised if out of memory

Compare With

Ada: N/A (AdaScript extension)

Implementation Note

Allocates a resource for the list.

dynamic_hash_tables.prepend( t, k, v )

 

Prepend string value v to the value under key k in the hash table. If the key does not exist, do nothing.

Example

dynamic_hash_tables.set( fruit_unit, "apples", "ushels" );
dynamic_hash_tables.prepend( fruit_unit, "apples", "b" );

Parameters

Param Mode Type Default Description
t in out dynamic_hash_tables.table required the table
k in string required the key
v in table value type required the string to prepend

Exceptions

An exception is raised if the value is the wrong type
An exception is raised if out of memory
An exception is raised if the value type is not a string

Restrictions

Not allowed with pragma ada_95

See Also

dynamic_hash_tables.append

Compare With

Ada: N/A (AdaScript extension)

Implementation Note

This is in accordance with memcached.

dynamic_hash_tables.remove( t, k )

 

Delete a key and the associated value from the hash table.

Example

dynamic_hash_tables.remove( fruit, "bad apples" );

Parameters

Param Mode Type Default Description
t in out dynamic_hash_tables.table required the table
k in string required the key to delete

Exceptions

-

Restrictions

Not allowed with pragma ada_95

See Also

dynamic_hash_tables.reset
dynamic_hash_tables.set

Compare With

Ada: N/A (AdaScript extension)

Implementation Note

This is in accordance with memcached.

dynamic_hash_tables.replace( t, k, v )

 

Replace the value v under key k in the hash table. If the key does not exist, do nothing.

Example

dynamic_hash_tables.replace( fruit, "apples", 23 );

Parameters

Param Mode Type Default Description
t in out dynamic_hash_tables.table required the table
k in string required the key
v in table value type required the new value

Exceptions

An exception is raised if the value is the wrong type
An exception is raised if out of memory

Restrictions

Not allowed with pragma ada_95

See Also

dynamic_hash_tables.set
dynamic_hash_tables.add

Compare With

Ada: N/A (AdaScript extension)

Implementation Note

This is in accordance with memcached.

dynamic_hash_tables.reset( t )

 

Delete all keys and associated values in the hash table..

Example

dynamic_hash_tables.reset( fruit );

Parameters

Param Mode Type Default Description
t in out dynamic_hash_tables.table required the table to clear

Exceptions

-

See Also

dynamic_hash_tables.remove

Compare With

Ada: Gnat.Dynamic_Hash_Tables.Reset

dynamic_hash_tables.set( t, k, v )

 

Assign the value v to the key k in the hash table. If the key does not exist, create it.

Example

dynamic_hash_tables.set( fruit, "apples", 21 );

Parameters

Param Mode Type Default Description
t in out dynamic_hash_tables.table required the table
k in string required the key
v in table value type required the new value

Exceptions

An exception is raised if the value is the wrong type
An exception is raised if out of memory

See Also

dynamic_hash_tables.add
dynamic_hash_tables.replace
dynamic_hash_tables.remove

Compare With

Ada: Gnat.Dynamic_Hash_Tables.Set

 
[Right Submenu]

 Summary

 arrays

 btree_io

 calendar

 cgi

 chains

 command_line

 db/ postgresql

 dbm

 directory_operations

 doubly_linked...

 dynamic_hash_...

 enums

 exceptions

 files

 gnat.cgi

 gnat.crc32

 hash_io

 lock_files

 memcache

 memcache.highread

 mysql

 mysqlm

 numerics

 os

 pen

 pen (OpenGL)

 records

 sound

 source_info

 stats

 strings

 System

 teams

 templates

 text_io

 units

[Back to Top] Back To Top [Small Forte Symbol]