![]() | This is an archive of past discussions about Associative array. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 1 |
In a tree where each node is an associative array, the keys can be references to other nodes in the tree rather than using a textual name. This can be implimented with the Tie function.
Hmmm, Do you mean that the values can be references to other associative sub-arrays, rather than the keys? For example, if I had to represent a Unix directory tree of just sub-directories, files and links to sub-directories then I would first walk the directory tree ignoring any links. Each directory would become an associative array,(AA), with directory entry names as keys and either file 'objects' as values for each file; or sub-AAs to represent sub-directories. A second walk of the directory tree would allow my to insert references to appropriate AA's as values for keys representing directory links.
In Python, AA values can be any object, so an AA with a recursive value example is just:
*** Python 2.4.2 (#67, Jan 17 2006, 15:36:03) [MSC v.1310 32 bit (Intel)] on win32. *** >>> dir1 = { 'file1': 'file1' } # AA creation with one file >>> dir1 {'file1': 'file1'} >>> dir1['link1'] = dir1 # The recursive link >>> dir1 {'file1': 'file1', 'link1': {...}} >>> dir1['link1'] # Accesses through the reference {'file1': 'file1', 'link1': {...}} >>> dir1['link1']['link1'] {'file1': 'file1', 'link1': {...}} >>> dir1['link1']['link1']['file1'] 'file1'
Again in Python; all non-mutable types are able to be AA keys. Other user-defined types can be used as AA keys if they define a hashing method. (The main mutable built-in type affected by the restriction is the Python list type. Lists are easily converted to the non-mutable tuple type for use as dictionary keys). --Paddy 07:39, 30 April 2006 (UTC)
Thomson Automation are nolonger selling there version of AWK. (follow the link). Sould it be removed from the AWK entry --Paddy 17:22, 22 September 2006 (UTC)
I undid a good-faith edit by User:Irishjugg that added a new section titled "Maps" and went as follows:
I have a number of issues with this addition, as follows:
EvanED 22:07, 10 December 2007 (UTC)
Edited again for a minor fix, and additional objection, EvanED 22:10, 10 December 2007 (UTC)
The article says the following about the difference:
While a regular array maps an index to an arbitrary data type such as integers, other primitive types, or even objects, an associative array's keys can be arbitrarily typed. The values of an associative array do not need to be the same type, although this is dependent on the programming language.
However, in my opinion, the difference between arrays and maps/dictionaries/hash tables lies on keys, not on values. At least in the programming languages I've programmed on so far, a traditional array is (conceptually) a special kind of map where indices are integers that are immediately consecutive (without "holes" or "jumps").
Comments? --Antonielly (talk) 19:06, 20 October 2008 (UTC)
The section under Association lists defines these to be a linked list of key-value pairs. This is consistent with the common definition of the term in Lisp/Scheme -- for example, [1]. The DADS page at [2] notes that the term is primarily associated with Lisp and the AI community.
User:Pgr94 recently made an edit [3] that doubts this, and the edit comment states that "decent implementations use balanced trees which give O(log n) look up time". However, the article itself lays out a contrast between efficient implementations -- balanced trees and hash tables -- in the immediately preceding section, and the inefficient linked-list-based implementation commonly called an association list. The DADS page, cited by User:Pgr94, makes no specific claim as to efficiency of an association list, and notes that they are often much smaller than general dictionaries. Indeed, an a-list is semantically equivalent to a tree-based dictionary, and the first page cited above notes that an a-list in practice (in one implementation) is in fact a true linked list.
There are two possible solutions to this -- either the claim that an association list might be tree-based is wrong, in which case User:Pgr94's edit should be reverted, or else the rest of the article needs to be made consistent with this new fact, since its structure sets up a contrast between linear-time and log-time implementations. My understanding of a-lists leans toward the former, i.e., that a true a-list is always a linked list and anything else is a dictionary but not an a-list. Thoughts?
cfallin|(talk) 11:33, 21 December 2008 (UTC)
Please don't confuse hash-tables with hashes. They are very different things. —Preceding unsigned comment added by 203.222.167.145 (talk) 02:19, 8 September 2009 (UTC)
I find this phrase confusing:
Ordering preservation: Balanced binary trees and skip lists preserve ordering — allowing one to efficiently iterate over the keys in order or to efficiently locate an association whose key is nearest to a given value. Hash tables do not preserve ordering and therefore cannot perform these operations as efficiently (they require the data to be sorted in a separate step).
I feel that the phrase should refer to the preservation of the "insertion order" when iterating over the collections of Keys or Values. But "key is nearest to a given value" supposes a kind order in the set of keys, and this is not part of the contract for the associative array abstract type. Note that Java JDK1.5 includes the class LinkedHashMap that preserves insertion order when browsing the map.
For the same reason I don't see the point to mention "range queries" for associative arrays, as they are not part of the contract. Maybe you could include among the "Specialized representations" the ones with sorted key sets. I mean, to define the abstract subtype "Sorted Associative Array" that would allow for range queries, and would exclude the simple has table implementations. —Preceding unsigned comment added by 83.43.153.47 (talk) 20:53, 20 November 2009 (UTC)
Hi. Between this article ("Associative array") and the article Attribute–value pair, some redirects are a bit messy:
These four redirects above currently point to Associative array.
These nine redirects above currently point to Attribute–value pair.
Previously, some of these redirects pointed to NoSQL, which I felt wasn't appropriate. This all seems a bit messy. Perhaps someone could take a look? --MZMcBride (talk) 19:20, 27 January 2013 (UTC)
Where is the PHP example??
"In PHP all arrays can be associative, except that the keys are limited to integers and strings and can only be a single level of subscripts."
Maybe I'm just reading this wrong, but can someone explain to me what this above statement means? --CheesyPuffs144 (talk) 02:27, 15 June 2008 (UTC)
$phonebook['contacts']['Sally Smart']['number'] = '555-9999';
Or at least I would if I could, but "PostScript" is not a recognised source language...
actionscript, ada, apache, applescript, asm, asp, autoit, bash, blitzbasic, bnf, c, c_mac, caddcl, cadlisp, cfdg, cfm, cpp, cpp-qt, csharp, css, d, delphi, diff, div, dos, eiffel, fortran, freebasic, gml, groovy, html4strict, idl, ini, inno, io, java, java5, javascript, latex, lisp, lua, matlab, mirc, mpasm, mysql, nsis, objc, ocaml, ocaml-brief, oobas, oracle8, pascal, perl, php, php-brief, plsql, python, qbasic, rails, reg, robots, ruby, sas, scheme, sdlbasic, smalltalk, smarty, sql, tcl, text, thinbasic, tsql, vb, vbnet, vhdl, visualfoxpro, winbatch, xml, xpp, z80
Any suggestions how to remedy this? nemo 11:35, 4 October 2007 (UTC)
It appears to be a recognized language now:
% Level 1 declaration
3 dict dup begin
/red (rouge) def
/green (vert) def
/blue (bleu) def
end
See Help: Wiki markup#Text formatting and Wikipedia: syntaxhighlight. --DavidCary (talk) 02:59, 24 May 2015 (UTC)
A recent edit([4]) makes this article say that both hash tables and search trees can solve the dictionary problem.
Previous versions of this article implied that there are some cases where a search tree cannot solve the dictionary problem (but a hash table could solve the problem).
Are there really cases where a search tree cannot solve the problem (forcing us to use hash tables in those cases)? If so, what are those cases? --DavidCary (talk) 15:50, 31 July 2016 (UTC)
is it missing information about Bash 4.0? Tech201805 (talk) 15:15, 25 June 2018 (UTC)
I have temporarily edit-protected this article (in, of course, the wrong version) because of the edit-warring going on over its lead. Please discuss the lead here rather than repeatedly reverting to your preferred versions. —David Eppstein (talk) 03:27, 9 August 2019 (UTC)
Dale Walker 1996 specifically states that formally, an ADT may be defined as a "class of objects whose logical behavior is defined by a set of values and a set of operations". In this sentense shall specifically means that you CAN, not that it's optional to do so. The entire idea behind an ADT is that you can take the mathematical definition and implement that definition in any programming language. We use math to define an ADT for one reason because it is the one and only Universal Language. This means that in the official cited literature, such as Dale Walker 1996, you define the data type using formal mathematical logic. Wikipedia is a secondary source, in which case they cite the official literature, which specifically makes mention of at least one set and at least one operation that can be performed on that set where you can manipulate an element of that set. A Collection is not an ADT because a collection is it doesn't spell out the implementation of a concrete data type because the elements of most math sets are often impossible to code. I came to this wiki because I'm writing the ASCII Data Specification to find the formal mathematical logic and language to reference for my specification. When I found it was not here it was like I was in an alternate reality. Every math article on Wikipedia is EXTREMELY detailed with set theory and logic and pretty graphs, and then there this wiki page, which makes no mention of the word set or an operation on a set outside of methods of a hash table, which isn't an ADT, it's a data structure. Every set has a domain and a codomain, so what's in the domain of the codomain of an Associative Array? I know because I'm a computer scientist, other people, however, do not know and when they go to the Wiki they should learn computer science, not computer programming.
The second order of business, the Wiki incorrectly states that a map is an Associative Array. That is like saying that all share circles. Every dictionary is a map but not every map is a dictionary. The article makes this mention because the C++ STL use map<Char,T> which is actually a map of strings to type T. That doesn't mean that a map is a dictionary. A map is like in set theory, a very well defined mathematical structure. The next question for the C++ folks is the map<Char,T> an Associative Array with Unique keys or is it an Associative List with duplicate keys? And so does this map do a map of integers to floating-point numbers? They called it map for a very silly reason and C++ isn't an ADT specification and thus should not be used to name the dictionary a map.
Fourth, a Key is not a thing in math. A string is a well defined mathematical construct. A "binding" to is not a math word, but mapping is. Its something you do when you map a key to a value in a dictionary.
As you can see, there are some MAJOR problems with this article that require it to be completely rewritten. What did Dale and Walker 1996 say about the dictionary? Let's see the citation. Here is a mathematical model of a dictionary that should be included in the Wiki. We have a domain with some unique strings, we have codomain, both sets include the empty set, and we map the strings in an onto configuration to the instances of objects in the codomain. This is not debatable, this is a mathematical fact.
— Preceding unsigned comment added by KabukiStarship (talk • contribs) 07:29, 12 August 2019 (UTC)
Here is a more scientifically correct definition, which I apologize about being rude, I'm new and drink too much coffee.
In computer science, an associative array, symbol table, dictionary, or collection of (unique-key, value) tuples is a surjective abstract data type that maps a set of unique strings in the domain, typically called Keys or Symbols, to instances of objects or the empty set in the codomain, typically called Values. The association between a Key and a Value, called a Key-value tuple, is referred to in Set theory as a "mapping", and the same word mapping may also be used to refer to the process of modifying an existing mapping, known as remapping and where remapping a Key to the empty set is referred to as Unmapping. A Key-value tuple is a Surjective mapping because each member of the Codomian is mapped to at least member of the domain such that for each member of the domain Key->Value.
Key->Value is the definition of a Surjection. — Preceding unsigned comment added by KabukiStarship (talk • contribs) 15:55, 12 August 2019 (UTC)
You are 100% wrong and I'm going to have to call out your credentials. I actually write ADT specifications. An associative array maps a string, no an integer, your example is of a map from an integer-> an integer. The term array in Assocaitiave Array means that each string acts like an array index. If you allow duplicate keys it's called an Associative List. These things have formal definitions. — Preceding unsigned comment added by KabukiStarship (talk • contribs) 16:33, 12 August 2019 (UTC)
You have an array of Key-Value tuples, it's surjective by all accounts. Look, please note the empty set is always mapped to the empty set because the function always returns the empty set: [{∅->∅} {"Foo"->∅} {"A"->3} {"B"->2} These are all Key-Value pairs. Every value in the domain, ∅, "Foo", "A", "B" all have Key-Value mappings into the codomain. Mind you, and Bijection is also called a Bijection surjective mapping because it is both Surjective and Bijective. — Preceding unsigned comment added by KabukiStarship (talk • contribs) 16:40, 12 August 2019 (UTC)
Key → Value is a one-to-one (injective) and onto (surjective) mapping of a set Key to a set Value. — Preceding unsigned comment added by KabukiStarship (talk • contribs) 16:42, 12 August 2019 (UTC)
I think I understand where the confusion is coming from. A Dictionary is a type of surjective map that contains a set of unique strings in the domain mapped to a set of objects or the empty set in the codomain. My definition needed to get unpacked.
Here is the compile error. Examples of Collection lists, sets, multisets, trees, and graphs. This was copy and paste from Wikipedia. The definition says it's a Dictionary is a Collection of key-value tuples... COMPILE ERROR. Insert definition: An Associative Array is a list, sets, multisets, trees or graphs of key-value tuples... THIS DOES NOT COMPUTE! So is it a tree of key-value tuples where the key only appears once?
Update: I have found source literature from the Association for Computing Machinery that proves my case. In fact, [1]. For example, page 208 of Erich 1982 reads "Let set be the category of sets with functions as morphisms. If S ~ I set I (the class of objects in set), we denote by sets the comma category whose objects are functions, 4 :.4 -~ S, S f'Lxed, and morphismsf:,4 --~ B are functionsf:~,/--, B such that .4 =fB (cf. Figure 1). Morphism composition is written from left to right, that is, xfg instead of the conventional g(f(x))."
Thank you, friend. Here is my dilemma. I'm writing an ASCII Data Specification, which is a concrete specification of ADT in contiguous memory-optimized for CPU cache performance and stack-to-heap operation. I need to find the formal mathematical definition of an associative array and other ADT so I can implement the Algebra for the ADT so I can get an ISO specification. A collection as an ADT is defined as a set that can be implemented as a concrete data type. The ASCII Data Specification starts out with an ASCII Map, which is a bijective map of one Plain-old-data type to another POD type, as in a map in set theory. An ASCII Map is not an associative array, nor will it ever be. In order to create an Associative Array, we use a mechanism that facilitates the creation of either a Dictionary or an Associative List. List in computer science allows duplicate entries while an array does. An Ascii List is a Type-Value tuple Array. We can make an array of strings called an ASCII Loom with an ASCII Map of most off, or we can make an ASCII Table, which is a bijective associative array that uses an ASCII Map to map to either an offset to the Value, or if it's negative then it's an index in the collisions pile. We can create an Associative List called an ASCII Book that uses an ASCII Loom for fastest push-back performance, then later convert it to an ASCII Table so you can use a hashtable after you've pushed all the Values back. All of these data types are ADTs. When you implement them you see that you need to have an Algebra in order to define what can and can't be in the collection on the target platform to create a collection. All of these data types have well-established definitions. Who's definition of a map is wrong? Is a C++ map just a map, or is it a map<Char,T> where they map strings to type T. It's not just called a map, and we have conflicting definitions. The only way to settle this is to cite the original source and provide the math proof so none of us can argue with it. — Preceding unsigned comment added by KabukiStarship (talk • contribs) 18:01, 13 August 2019 (UTC)
It's not incoherent if you are a computer scientist. A map is not a dictionary, a dictionary is a type of map; there is nothing incoherent about that; a shape is not a circle, and a circle is a shape but when you reverse the order of the words you completely alter its meaning and make it incoherent. The Wiki currently reads a "dictionary is an abstract data type composed of a collection of (key, value) pairs, such that each possible key appears at most once in the collection." When you define something you're supposed to start out with "a dictionary is a...", in which case you would say it's a type of map. An object that "contains a collection unique key-value tuples" is quite a bit different than a map of Key-Value tuples.
The reason I need the algebra for the ASCII Data Specifcaiton is that I am able to prove using many methods, such as Design by Contract, that an ADT meets the ADT specification, and this should be in Wiki because it's part of the Computer Science of an Associate array, which is a type of map, not a map. There is an algebra that I can use a Unit test framework that allows me to prove mathematically that the ADT performs the functions[AssociativeArraySources 1]. This then allows me to get standardized for use in aerospace technology. I cite sources, others have only voiced opinions. You can't just voice an opinion, you have to prove things and cite sources like I have.
If the map is a component that exists in the List, Array of Strings, Associative List, Associative Array, that means the Associative Array is not a map; I can factor the Algebra out. When the C++ Standards Committee named it map they meant a math map of a string to type T, they never intended to call a dictionary a map, where is the source of this false information? Cite who originally started calling it a map and you'll see it's a secondary source, not a primary source, and C++ is NOT considered a primary source Computer Science terminology. The map is a set in the domain with mappings, not bindings into the codomain set; if I'm right about that the wiki is wrong. The Values are the codomain; prove me wrong don't just voice an opnion. I didn't make this up, it's well-established math terminology. A collection, on the other hand, is defined on Wikipedia as:
"In computer science, a collection or container is a grouping of some variable number of data items (possibly zero) that have some shared significance to the problem being solved and need to be operated upon together in some controlled fashion."
This definition differs greatly from the Dale Walker 1996 definition that "class of objects whose logical behavior is defined by a set of values and a set of operations". So what is the set of values and what is the set of operations? This is from Wikipedia. The Wiki for ADT says:
"In computer science, an abstract data type (ADT) is a mathematical model for data types, where a data type is defined by its behavior (semantics) from the point of view of a user of the data, specifically in terms of possible values, possible operations on data of this type, and the behavior of these operations."
A Collection by definition isn't a mathematical model for an associative array, that model would call it a type of map and refer to it as mapping as everyone else in math does. A tree is a type of Collection, and you can make a dictionary out of it, but the sets aren't the same, the tree is a parent-child_left-child_right-key-value 5-tuple, not a key-value 2-tuple, and the tree is then a morphism of the map, which maps it a map, not a collection of key-value tuples. That makes the definition on Wikipedia incoherent. I did author the world's fastest integer-to-string algorithm, the Puff Algoihrm, and the fastest pointer alignment algorithm (Google Puff Algoihrm and look in the wiki), I have some street cred in Computer Science with discrete math.
I can lie about having a Ph.D. too, but the fact is that I did optimize out more than half of the division instructions and I did reduce the number of instructions of the pointer alignment algoihrm to 3 instructions using discrete math and I did cite proof and you did cite my name. I'm the only one here who has any credentials writing ADT specifications. Yes or no questions: Do not respond unless you address each point and cite the point:
1. Is a map implementation of the concrete implementation of the Abstract Data Type called a Dictionary? (hint: Yes)
2. Is an ADT a mathematical model for a data type? (hint: yes)
3. Is a map a mathematical model? (hint: yes)
4. Can I define a dictionary as a map of unique keys int the domain to values in the domain? (hint: yes)
5. Is it proper to define a map as a map of unique keys int the domain to values in the domain? (hint: no)
6. Is a concrete implementation of an ADT called a dictionary the name of the ADT called a dictionary? (hint: no) — Preceding unsigned comment added by KabukiStarship (talk • contribs) 23:46, 16 August 2019 (UTC)
A map is a concrete implementation of the ADT called a dictionary. A normal Array in C++, where the domain is integer indexes starting at 0, the model for that is a map... that makes it scientifically inaccurate. I want to see names and degrees. I'm the only one with any research innovations in this field here. Cite who first started calling it a map else it's false. — Preceding unsigned comment added by KabukiStarship (talk • contribs) 23:43, 16 August 2019 (UTC)
Also answer these:
6. Is a collection of type-value tuples with no mappings from the key to the value a map? (hint: no)
7. Is mapping the proper math term for the math model called a map? (hint: yes)
8. If it's called a mapping then is it a map? (hint: yes)
9. Is the name of a Concrete implementation of an ADT (i.e. map) the same thing as the ADT? (hint: no)
Thus we must conclude that not every doctor is correct about everything, and the world is a better place when we all use the proper scientific terms to describe a math model (like an ADT). I do write ADT Specifications thank you very much, but I'm not a doctor and I am looking for help. So I have a right to be on record with my science. — Preceding unsigned comment added by KabukiStarship (talk • contribs) 00:18, 17 August 2019 (UTC)
Here is all the proof we need here, it doesn't matter about pull, math geeks UNITE! The C++14 Standard Section 23.4.4 defines a "map is an associative container that supports unique keys (contains at most one of each key value) and provides for fast retrieval of values of another type T based on the keys. The map class supports bidirectional iterators."[AssociativeArrayProof 1]
The C++ Standard defines a concrete implementation of the dictionary ADT and the ASCII Data Spec defines the memory layout for a POD-to-POD map that we then use to create a Concrete implementation of the dictionary ADT, and soon it will have the Axioms to verify conformance to the ADT spec, and thus they are both concrete implementations and neither is the ADT known as a dictionary. I apologize for being rude and for the wall of text, but it is a verifiably true and worthy debate.
How is a value accessed in Lisp? --Hirzel
(multiple-value-bind (result success) (gethash 'moose *some-hash-table*) (if success (print result) (print "Not found.")))
It is not correct to say that Lisp uses alists for associative arrays. Common Lisp has a native, typed, hash table type which is the closest match to other languages' dictionaries or hashes. Alists are simply a shape of list for which there are some associative-like operations; they're used where a hash table would be too much overhead or complexity, not as a replacement for more general associative arrays. --FOo 16:16, 16 July 2003 (UTC)
I've done some pretty severe reorganization of this page. As usual I wanted to separate the theoretical stuff from the language-specific stuff. I also added a lot more about data structures used to implement associative arrays and the relative tradeoffs, and some links to the STL pages about the abstract data type and their hash table/red-black tree map implementations. Added a little note about Lua also. I hope my splitting apart and editing of the associative list section pleased the one person above, and didn't anger anyone. I'd appreciate any feedback on my changes.
Derrick Coetzee 03:01, 25 November 2003 (UTC)
---
To 62.134.120.20, if you read this, I feel like many of the links you added were either:
While I encourage effective cross-linking of material, bad cross-linking frustrates and obscures. Please exercise more discretion in the future when adding links. I refer you to some of Wikipedia's policy on links:
Derrick Coetzee 08:28, 6 December 2003 (UTC)
I note that someone change the Python example loop to:
for name in phonebook:
instead of:
for key in phonebook
I deliberately choose key to emphasize that iterating over the phonebook dict iterates over all its keys. — Preceding unsigned comment added by Paddy3118 (talk • contribs) 15:22, 17 April 2006 (UTC)
Cite error: There are <ref group=proof>
tags on this page, but the references will not show without a {{reflist|group=proof}}
template (see the help page).
Cite error: There are <ref group=AssociativeArraySources>
tags on this page, but the references will not show without a {{reflist|group=AssociativeArraySources}}
template (see the help page).
Cite error: There are <ref group=AssociativeArrayProof>
tags on this page, but the references will not show without a {{reflist|group=AssociativeArrayProof}}
template (see the help page).