Associative table

In Data-processing, a associative table (also called dictionary or table of association ) is an abstract type from data composed of a finished unit of keys and a unit finished of values, where each key is associated with a value. The concept of associative table is thus close to that of function to field finished in mathematics.

From the point of view of the programmer, the associative table can be seen like a generalization of the table: whereas the traditional table associates consecutive entireties with values of a certain type, the associative table associates values of an arbitrary type with values of another type.

The operations usually provided by an associative table are:

  • addition : association of a new value to a new key;
  • modification : association of a new value to an old key;
  • suppression: removal of a key;
  • research : determination of the value associated with a key, if it exists.

Examples

One can see a phone book like an associative table, where the names constitute the keys and the phone numbers the values. Another example is that of a dictionary (with the traditional direction), where the words are the keys and the definitions the values. A Database can be also seen like a generalization of the concept of associative table.

Structures of data for the associative tables

The associative tables are generally used when research operation is most frequent. For this reason, the design generally privileges this operation, with the detriment of the effectiveness of the addition and the occupation memory by report/ratio other structures of data (such as the lists of association). In rare cases, an associative table can be implemented on a material level (see addressable Mémoire by contents).

Effective representations

There are mainly two structures of data to represent the associative tables: the Table of chopping and the Tree balanced. The advantages and respective disadvantages of these two solutions are the following:
  • the tables of chopping have a better complexity on average for insertion and research (O (1)), whereas the balanced trees have a better complexity in worst case (O (log ( N )), instead of O ( N ) for the tables of chopping).

  • the tables of chopping have a representation memory generally more compact.
  • the balanced trees can easily provide structures of persistent data , which is particularly proposed in the functional Programmation.
  • the tables of chopping require the definition of good a Fonction of chopping, which can be difficult to realize in certain cases, whereas the balanced trees do not require of a total Ordre on the keys. Conversely, the tables of choppings can be used on not ordered keys.
  • the balanced trees preserve the order of the keys, in particular making it possible to carry out a course of the keys in the order or to effectively locate a key close to a given value. The tables of chopping, on the other hand, do not preserve the order of the keys (when there exists).

Lists of association

A manner simple, but generally ineffective, to carry out an associative table consists in using a list of association , i.e. a chained Liste of pairs key-value. Research then consists in traversing the list until finding a key given; it is thus of complexity O ( N ). Although ineffective in general, the list of association has the following advantages however:
  • No function on the keys is necessary (such as a relation of order or a function of chopping).
  • the addition is carried out in constant time (when it is carried out top of the list).
  • For very small associative tables, the lists of associations can use less resources than other structures of data.

Specialized representations

If the keys have a particular type, it is sometimes possible to obtain better performances by using a specialized structure of data. For example, it is possible to use a Arbre of Patricia if the keys are entireties (when the keys are too sparse so that a traditional table can be used). In a more general way, a '' sorts '' can be used as soon as the keys have a structure of words. Many comparisons then are avoided when several keys have common prefixes, which is the case for example in the tables of Routage.

Support in the computer programming languages

PHP

Source code using an associative table: $dico = array (" lundi" =>" dodo" , " mardi" =>" dodo" , " mercredi" =>" resto" ); echo $dico; foreach ($dico ace $key=>$value) { echo " The $key it is $value." ; }

Exit screen: dodo Monday it is dodo Tuesday it is dodo Wednesday it is restaurant

C++

Source code C++ using an associative table via the class map of the standard Library:
  1. include
  2. include
using namespace std;

int hand () { map repertory; Dupont" repertory; = " 01.02.03.04 .05" ; Martin" repertory; = " 02.03.04.05 .06" ; Durand" repertory; = " 03.04.05.06 .07" ; return 0; }

The associative table above is also called dictionary in particular because it makes it possible to make fast research, without traversing the whole table.

Objectify Caml

The language Objective Caml provides three kinds of associative tables in its standard library. Simplest is a list of pairs:
  1. let m = Smart" , " 555-9999" ; " John Doe" , " 555-1212" ;
" J. Random Hacker" , " 553-1337"]; ; valley m: (string * string) list = Smart" , " 555-9999"); (" John Doe" , " 555-1212"); (" J. Random Hacker" , " 553-1337")]
  1. List.assoc "John Doe" m; ;
-: string = " 555-1212"

The second is a polymorphic Table of chopping:

  1. let m = Hashtbl.create 3; ;
valley m: (“_a,” _b) Hashtbl.t =
  1. Hashtbl.add m " Sally Smart" " 555-9999" ;
Hashtbl.add m " John Doe" " 555-1212" ; Hashtbl.add m " J. Random Hacker" " 553-1337" ; ; -: links = ()
  1. Hashtbl.find m " John Doe" ; ;
-: string = " 555-1212"

Lastly, the last is a purely applicatif dictionary (realized by trees AVL):

  1. include (Map.Make (String)); ;
  1. let m = add " Sally Smart" " 555-9999" empty
let m = add " John Doe" " 555-1212" m let m = add " J. Random Hacker" " 553-1337" m; ; valley m: string T =
  1. find " John Doe" m; ;
-: string = " 555-1212"

The lists of pairs and the dictionaries are structures of persistent data, because Purement functional them. The tables of chopping are contrary to the structures of imperative data , better effectiveness that the lists and the AVL in general.

Random links:Ponds of Holland | Sternocleidomastoid muscle | Route main road 319 | Third district of the Low-Rhine | Tiger Sharks de Tallahassee