This commit is contained in:
Ingy döt Net 2013-04-10 16:57:12 -07:00
parent 518da4a923
commit 764da6cbbb
6144 changed files with 83610 additions and 11 deletions

View file

@ -0,0 +1 @@
#include <map>

View file

@ -0,0 +1,26 @@
#include <map>
#include <iostreams>
int main()
{
// Create the map.
std::map<int, double> exampleMap;
// Choose our key
int myKey = 7;
// Choose our value
double myValue = 3.14;
// Assign a value to the map with the specified key.
exampleMap[myKey] = myValue;
// Retrieve the value
double myRetrievedValue = exampleMap[myKey];
// Display our retrieved value.
std::cout << myRetrievedValue << std::endl;
// main() must return 0 on success.
return 0;
}

View file

@ -0,0 +1 @@
std::map<A, B> exampleMap

View file

@ -0,0 +1 @@
std::map<int, double> exampleMap

View file

@ -0,0 +1 @@
exampleMap[7] = 3.14

View file

@ -0,0 +1,3 @@
int myKey = 7;
double myValue = 3.14;
exampleMap[myKey] = myValue;

View file

@ -0,0 +1 @@
exampleMap.insert(std::pair<int, double>(7,3.14));

View file

@ -0,0 +1 @@
exampleMap.insert(std::make_pair(7,3.14));

View file

@ -0,0 +1 @@
myValue = exampleMap[myKey]

View file

@ -0,0 +1,7 @@
double myValue = 0.0;
std::map<int, double>::iterator myIterator = exampleMap.find(myKey);
if(exampleMap.end() != myIterator)
{
// Return the value for that key.
myValue = myIterator->second;
}

View file

@ -0,0 +1,2 @@
System.Collections.HashTable map = new System.Collections.HashTable();
map["key1"] = "foo";

View file

@ -0,0 +1,2 @@
Dictionary<string, string> map = new Dictionary<string,string>();
map[ "key1" ] = "foo";

View file

@ -0,0 +1 @@
var map = new Dictionary<string, string> {{"key1", "foo"}};

View file

@ -0,0 +1,4 @@
<cfset myHash = structNew()>
<cfset myHash.key1 = "foo">
<cfset myHash["key2"] = "bar">
<cfset myHash.put("key3","java-style")>

View file

@ -0,0 +1,13 @@
;; default :test is #'eql, which is suitable for numbers only,
;; or for implementation identity for other types!
;; Use #'equalp if you want case-insensitive keying on strings.
(setf my-hash (make-hash-table :test #'equal))
(setf (gethash "H2O" my-hash) "Water")
(setf (gethash "HCl" my-hash) "Hydrochloric Acid")
(setf (gethash "CO" my-hash) "Carbon Monoxide")
;; That was actually a hash table, an associative array or
;; alist is written like this:
(defparameter *legs* '((cow . 4) (flamingo . 2) (centipede . 100)))
;; you can use assoc to do lookups and cons new elements onto it to make it longer.

View file

@ -0,0 +1,4 @@
void main() {
auto hash = ["foo":42, "bar":100];
assert("foo" in hash);
}

View file

@ -0,0 +1,5 @@
m = { => } # empty, future inserted keys will be ordered
h = { : } # empty, future inserted keys will not be ordered
m = { 'foo' => 42, 'bar' => 100 } # with ordered keys
h = { 'foo' : 42, 'bar' : 100 } # with unordered keys

View file

@ -0,0 +1,19 @@
program AssociativeArrayCreation;
{$APPTYPE CONSOLE}
uses Generics.Collections;
var
lDictionary: TDictionary<string, Integer>;
begin
lDictionary := TDictionary<string, Integer>.Create;
try
lDictionary.Add('foo', 5);
lDictionary.Add('bar', 10);
lDictionary.Add('baz', 15);
lDictionary.AddOrSetValue('foo', 6); // replaces value if it exists
finally
lDictionary.Free;
end;
end.

View file

@ -0,0 +1,5 @@
[].asMap() # immutable, empty
["one" => 1, "two" => 2] # immutable, 2 mappings
[].asMap().diverge() # mutable, empty
["one" => 2].diverge(String, float64) # mutable, initial contents,
# typed (coerces to float)

View file

@ -0,0 +1,8 @@
#define std'dictionary'*.
#define std'collections'*.
#symbol Program =
[
#var map := Dictionary.
map append &dictionary_key:"foo" &content:"bar".
].