Associative Array Data Structure: Difference between revisions

From GM-RKB
Jump to navigation Jump to search
(Importing converted wikitext)
 
No edit summary
Line 1: Line 1:
#REDIRECT [[Associative Array]]
An [[Associative Array Data Structure]] is a [[collection data structure]] that facilitates the storage, update, and retrieval of [[key-value pair]]s of the same [[key type]].
* <B><U>AKA</U>:</B> [[Key-Value Table]], [[Associative Container]], [[Map Structure]], [[Dictionary Structure]], [[Lookup Table]].
* <B><U>Context</U>:</B>
** It can (typically) be accessed natively from a [[Programming Language]].
** It can be implemented with:
*** a [[Hash Table]].
*** a [[Self-Balancing Binary Search Tree]].
* <B><U>Example(s)</U>:</B>
** a [[Perl Associative Array]].
** a [[Python Dictionary Data Structure]].
** a [[Java Associative Array]]/[[Java Map]].
** a [[Scala Associative Array]]/[[Scala Map]].
** a [[Cassandra Associative Array]].
* <B><U>Counter-Example(s)</U>:</B>
** an [[Array Data Structure]].
* <B><U>See</U>:</B> [[Hash Data Structure]].
----
----
==References ==
 
===2013===
* http://rosettacode.org/wiki/Associative_array
** An '''associative array''' is a collection indexed by arbitrary data types, not just small integers. Whereas an [[array]] is typically implemented as many same-sized items stored in a contiguous block of memory, an associative array must be implemented via a more complex data structure, such as a hash table, a list, or some other type of map.        <P>          The terminology and semantics of these vary among different programming languages.  For example in Perl and Ruby they are called “''hashes''” (from abbreviating “hash table”, the underlying implementation) while in Python, Objective-C, and Smalltalk they are called “''dictionaries''” (by analogy to the normal English usage of the term: an indexed reference by which keys (words) are associated with values (definitions)).  In Lua they are called “''tables''”. In Java, C++, and Go they are called “''maps''”.        <P>          The semantics differ as well.  While all of these allow the programmer to associate some sort of key with some sort of value they can differ considerably in how they evaluate the key and what sorts of values can be stored.        <P>          For example in [[awk]] and [[Perl]] the keys are evaluated (as “scalars” in Perl terminology).  Thus the the keys <tt>"1"</tt> (a string) and <tt>1</tt> (an integer) and <tt>1.0</tt> (a real or floating point number) would all evaluate into equivalent keys.  By contrast these would each be distinct in Python.  In a [[Python]] dictionary any immutable object (strings, integer, floats) and any object/class which implements the <tt>__hash__</tt> special method can be used as a key.  Values can be references to any objects (including functions, classes, class methods which are all "first class objects" in that language).  In [[Lua]], a table is a complex data structure which can be used to implement arrays, objects and associative arrays (integer key values are implicitly treated like indices into a virtual array, those with values that reference functions are methods, those which reference other types of objects are attributes or members).        <P>          Associative arrays are used as the underlying data structure for objects in a number of languages.  Python objects normally have a visible <tt>__dict__</tt> attribute by which its methods and other attributes can be accessed indirectly. PHP objects can be cast into associative arrays, and vice versa, with the keys and values corresponding to property names and values of the object. Perl objects are references of (usually) hashes. And (as described above) Lua objects are implemented as tables (functions and other objects are “first class objects” which an be assigned to keys and passed around as arguments, as with Python). Similarly, in JavaScript the concepts of associative array and object are the same, since JavaScript lacks a separate "associative array" type, and object attributes can be accessed using subscript operator with the attribute name as a string.
 
===2011===
* http://en.wikipedia.org/wiki/Collection_%28computing%29#Associative_arrays
** An [[associative array]] or "lookup table" acts like a dictionary, providing a "value" (like a definition) in response to a lookup on a "key" (like a word).  The "value" might be a reference to a compound data structure.  A [[hash table]] is usually an efficient implementation.
* http://en.wikipedia.org/wiki/Associative_array
** In [[computer science]], an '''associative array''' (also called a '''map''' or a '''dictionary''') is an [[abstract data type]] composed of a [[Collection (computing)|collection]] of (key,value) pairs, such that each possible key appears at most once in the collection. Operations associated with this data type allow the addition of pairs to the collection, the removal of pairs from the collection, the modification of the values of existing pairs, and the lookup of the value associated with a particular key.<ref name="gt">{{citation|contribution=9.1 The Map Abstract Data Type|title=Data Structures & Algorithms in Java|last1=Goodrich|first1=Michael T.|author1-link=Michael T. Goodrich|last2=Tamassia|first2=Roberto|author2-link=Roberto Tamassia|publisher=Wiley|edition=4th|year=2006|pages=368–371}}.</ref><ref name="ms">{{citation|contribution=4 Hash Tables and Associative Arrays|title=Algorithms and Data Structures: The Basic Toolbox|first1=Kurt|last1=Mehlhorn|author1-link=Kurt Mehlhorn|first2=Peter|last2=Sanders|publisher=Springer|year=2008|pages=81–98}}.</ref>  <P>  The '''dictionary problem''' is the task of designing a [[data structure]] that implements an associative array. A standard solution to the dictionary problem is a [[hash table]]; in some cases it is also possible to solve the problem using directly addressed [[Array data structure|array]]s, [[binary search tree]]s, or other more specialized structures.<ref name="gt"/><ref name="ms"/><ref name="clrs">{{citation | last1 = Cormen | first1 = Thomas H. | author1-link=Thomas H. Cormen | coauthors = [[Charles E. Leiserson|Leiserson, Charles E.]]; [[Ron Rivest|Rivest, Ronald L.]]; [[Clifford Stein|Stein, Clifford]] | title = [[Introduction to Algorithm]]s | edition = 2nd | year = 2001 | publisher = [[MIT Press]] and [[McGraw-Hill]] | isbn=0-262-03293-7 | chapter = 11 Hash Tables | pages = 221–252}}.</ref>  <P> Many programming languages include associative arrays as [[primitive data type]]s, and they are available in [[software library|software libraries]] for many others. [[Content-addressable memory]] is a form of direct hardware-level support for associative arrays.  <P> Associative arrays have many applications including such fundamental [[programming pattern]]s as [[memoization]]
<references/>
 
===2010===
* ([[2010_ProgramminginScala|Odersky & al, 2010]]) &rArr; [[Martin Odersky]], [[Lex Spoon]], and [[Bill Venners]]. ([[2010]]). "[http://f3.tiera.ru/2/Cs_Computer%20science/CsPl_Programming%20languages/Odersky%20M.,%20Spoon%20L.,%20Venners%20B.%20Programming%20in%20Scala..%20A%20Comprehensive%20Step-by-Step%20Guide%20%282ed.,%20Artima%20Inc,%202011%29%28ISBN%200981531644%29%28O%29%2 Programming in Scala, 2nd edition]."  Artima. ISBN:0981531644
** QUOTE: One common characteristic of these [[scripting language|languages]], which is relevant for the example above, is that they each support an [[associative map data structure|"associative map" construct]] in the [[[programming language syntax|syntax of the language]]. [[Associative map]]s are very useful because they help keep [[program]]s [[legible code|legible]] and [[concise code|concise]]. However, sometimes you might not agree with their "one size fits all" philosophy, because you need to control the properties of the [[associative map|maps]] you use in your program in a more fine-grained way. [[Scala]] gives you this fine-grained control if you need it, because [[Scala Associative Map Variable|maps in Scala]] are not [[language syntax]]. They are [[library abstraction]]s that you can [[extended class|extend]] and [[adapted class|adapt]].
 
===2009===
* http://en.wikipedia.org/wiki/Associative_array
** ... From the perspective of a computer programmer, an associative array can be viewed as a generalization of an [[Array data type|array]]. While a regular array maps an integer key ([[Index (information technology)|index]]) to a value of arbitrary [[data type]], an associative array's keys can also be arbitrarily typed. In some [[programming language]]s, the keys of an associative array do not even need to be of the same type.
 
----


__NOTOC__
__NOTOC__
[[Category:Concept]]

Revision as of 20:34, 31 July 2014

An Associative Array Data Structure is a collection data structure that facilitates the storage, update, and retrieval of key-value pairs of the same key type.



References

2013

  • http://rosettacode.org/wiki/Associative_array
    • An associative array is a collection indexed by arbitrary data types, not just small integers. Whereas an array is typically implemented as many same-sized items stored in a contiguous block of memory, an associative array must be implemented via a more complex data structure, such as a hash table, a list, or some other type of map.

      The terminology and semantics of these vary among different programming languages. For example in Perl and Ruby they are called “hashes” (from abbreviating “hash table”, the underlying implementation) while in Python, Objective-C, and Smalltalk they are called “dictionaries” (by analogy to the normal English usage of the term: an indexed reference by which keys (words) are associated with values (definitions)). In Lua they are called “tables”. In Java, C++, and Go they are called “maps”.

      The semantics differ as well. While all of these allow the programmer to associate some sort of key with some sort of value they can differ considerably in how they evaluate the key and what sorts of values can be stored.

      For example in awk and Perl the keys are evaluated (as “scalars” in Perl terminology). Thus the the keys "1" (a string) and 1 (an integer) and 1.0 (a real or floating point number) would all evaluate into equivalent keys. By contrast these would each be distinct in Python. In a Python dictionary any immutable object (strings, integer, floats) and any object/class which implements the __hash__ special method can be used as a key. Values can be references to any objects (including functions, classes, class methods which are all "first class objects" in that language). In Lua, a table is a complex data structure which can be used to implement arrays, objects and associative arrays (integer key values are implicitly treated like indices into a virtual array, those with values that reference functions are methods, those which reference other types of objects are attributes or members).

      Associative arrays are used as the underlying data structure for objects in a number of languages. Python objects normally have a visible __dict__ attribute by which its methods and other attributes can be accessed indirectly. PHP objects can be cast into associative arrays, and vice versa, with the keys and values corresponding to property names and values of the object. Perl objects are references of (usually) hashes. And (as described above) Lua objects are implemented as tables (functions and other objects are “first class objects” which an be assigned to keys and passed around as arguments, as with Python). Similarly, in JavaScript the concepts of associative array and object are the same, since JavaScript lacks a separate "associative array" type, and object attributes can be accessed using subscript operator with the attribute name as a string.

2011

2010

2009