CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
|
|
@ -0,0 +1 @@
|
|||
#include <map>
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
std::map<A, B> exampleMap
|
||||
|
|
@ -0,0 +1 @@
|
|||
std::map<int, double> exampleMap
|
||||
|
|
@ -0,0 +1 @@
|
|||
exampleMap[7] = 3.14
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
int myKey = 7;
|
||||
double myValue = 3.14;
|
||||
exampleMap[myKey] = myValue;
|
||||
|
|
@ -0,0 +1 @@
|
|||
exampleMap.insert(std::pair<int, double>(7,3.14));
|
||||
|
|
@ -0,0 +1 @@
|
|||
exampleMap.insert(std::make_pair(7,3.14));
|
||||
|
|
@ -0,0 +1 @@
|
|||
myValue = exampleMap[myKey]
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
System.Collections.HashTable map = new System.Collections.HashTable();
|
||||
map["key1"] = "foo";
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Dictionary<string, string> map = new Dictionary<string,string>();
|
||||
map[ "key1" ] = "foo";
|
||||
|
|
@ -0,0 +1 @@
|
|||
var map = new Dictionary<string, string> {{"key1", "foo"}};
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<cfset myHash = structNew()>
|
||||
<cfset myHash.key1 = "foo">
|
||||
<cfset myHash["key2"] = "bar">
|
||||
<cfset myHash.put("key3","java-style")>
|
||||
|
|
@ -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.
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
void main() {
|
||||
auto hash = ["foo":42, "bar":100];
|
||||
assert("foo" in hash);
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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.
|
||||
|
|
@ -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)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#define std'dictionary'*.
|
||||
#define std'collections'*.
|
||||
|
||||
#symbol Program =
|
||||
[
|
||||
#var map := Dictionary.
|
||||
map append &dictionary_key:"foo" &content:"bar".
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue