| 1 |
/********************************************************* |
|---|
| 2 |
Copyright: (C) 2008-2010 by Steven Schveighoffer. |
|---|
| 3 |
All rights reserved |
|---|
| 4 |
|
|---|
| 5 |
License: Boost Software License version 1.0 |
|---|
| 6 |
|
|---|
| 7 |
Permission is hereby granted, free of charge, to any person or organization |
|---|
| 8 |
obtaining a copy of the software and accompanying documentation covered by |
|---|
| 9 |
this license (the "Software") to use, reproduce, display, distribute, |
|---|
| 10 |
execute, and transmit the Software, and to prepare derivative works of the |
|---|
| 11 |
Software, and to permit third-parties to whom the Software is furnished to |
|---|
| 12 |
do so, all subject to the following: |
|---|
| 13 |
|
|---|
| 14 |
The copyright notices in the Software and this entire statement, including |
|---|
| 15 |
the above license grant, this restriction and the following disclaimer, must |
|---|
| 16 |
be included in all copies of the Software, in whole or in part, and all |
|---|
| 17 |
derivative works of the Software, unless such copies or derivative works are |
|---|
| 18 |
solely in the form of machine-executable object code generated by a source |
|---|
| 19 |
language processor. |
|---|
| 20 |
|
|---|
| 21 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 22 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 23 |
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
|---|
| 24 |
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
|---|
| 25 |
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
|---|
| 26 |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|---|
| 27 |
DEALINGS IN THE SOFTWARE. |
|---|
| 28 |
|
|---|
| 29 |
**********************************************************/ |
|---|
| 30 |
module dcollections.model.Map; |
|---|
| 31 |
|
|---|
| 32 |
public import dcollections.model.Keyed; |
|---|
| 33 |
|
|---|
| 34 |
/** |
|---|
| 35 |
* A Map collection uses keys to map to values. This can only have one |
|---|
| 36 |
* instance of a particular key at a time. |
|---|
| 37 |
*/ |
|---|
| 38 |
interface Map(K, V) : Keyed!(K, V) |
|---|
| 39 |
{ |
|---|
| 40 |
/** |
|---|
| 41 |
* set all the elements from the given keyed iterator in the map. Any key |
|---|
| 42 |
* that already exists will be overridden. |
|---|
| 43 |
* |
|---|
| 44 |
* Returns this. |
|---|
| 45 |
*/ |
|---|
| 46 |
Map set(KeyedIterator!(K, V) source); |
|---|
| 47 |
|
|---|
| 48 |
/** |
|---|
| 49 |
* set all the elements from the given associative array in the map. Any |
|---|
| 50 |
* key that already exists wil be overridden. |
|---|
| 51 |
* |
|---|
| 52 |
* Returns this. |
|---|
| 53 |
*/ |
|---|
| 54 |
Map set(V[K] source); |
|---|
| 55 |
|
|---|
| 56 |
/** |
|---|
| 57 |
* Remove all the given keys from the map. |
|---|
| 58 |
* |
|---|
| 59 |
* return this. |
|---|
| 60 |
*/ |
|---|
| 61 |
Map remove(Iterator!(K) subset); |
|---|
| 62 |
|
|---|
| 63 |
/** |
|---|
| 64 |
* Remove all the given keys from the map. |
|---|
| 65 |
* |
|---|
| 66 |
* return this. |
|---|
| 67 |
*/ |
|---|
| 68 |
Map remove(K[] subset...); |
|---|
| 69 |
|
|---|
| 70 |
version(testcompiler) |
|---|
| 71 |
{ |
|---|
| 72 |
|
|---|
| 73 |
/** |
|---|
| 74 |
* Remove a range of keys from the map. |
|---|
| 75 |
* |
|---|
| 76 |
* return this. |
|---|
| 77 |
* |
|---|
| 78 |
* TODO: rename to removeKeys |
|---|
| 79 |
*/ |
|---|
| 80 |
auto removeRange(R)(R range) if (isInputRange!R && is(isElementType!R == K)) |
|---|
| 81 |
{ |
|---|
| 82 |
foreach(k; range) |
|---|
| 83 |
removeAt(k); |
|---|
| 84 |
return this; |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
/** |
|---|
| 89 |
* Remove all the keys that are not in the given iterator. |
|---|
| 90 |
* |
|---|
| 91 |
* returns this. |
|---|
| 92 |
*/ |
|---|
| 93 |
Map intersect(Iterator!(K) subset); |
|---|
| 94 |
|
|---|
| 95 |
/** |
|---|
| 96 |
* Remove all the keys that are not in the given array. |
|---|
| 97 |
* |
|---|
| 98 |
* returns this. |
|---|
| 99 |
*/ |
|---|
| 100 |
Map intersect(K[] subset...); |
|---|
| 101 |
|
|---|
| 102 |
/** |
|---|
| 103 |
* Get a set of the keys that the map contains. This is not a copy of the |
|---|
| 104 |
* keys, but an actual "window" into the keys of the map. If you add |
|---|
| 105 |
* values to the map, they will show up in the keys iterator. |
|---|
| 106 |
* |
|---|
| 107 |
* This is not in Keyed, because some Keyed containers have simple index |
|---|
| 108 |
* keys, and so this would be not quite that useful there. |
|---|
| 109 |
*/ |
|---|
| 110 |
Iterator!(K) keys(); |
|---|
| 111 |
|
|---|
| 112 |
/** |
|---|
| 113 |
* clear all elements in the collection (part of collection |
|---|
| 114 |
* pseudo-interface) |
|---|
| 115 |
*/ |
|---|
| 116 |
Map clear(); |
|---|
| 117 |
|
|---|
| 118 |
/** |
|---|
| 119 |
* dup the collection (part of collection pseudo-interface) |
|---|
| 120 |
*/ |
|---|
| 121 |
Map dup(); |
|---|
| 122 |
|
|---|
| 123 |
/** |
|---|
| 124 |
* covariant set (from Keyed) |
|---|
| 125 |
*/ |
|---|
| 126 |
Map set(K key, V value); |
|---|
| 127 |
|
|---|
| 128 |
/** |
|---|
| 129 |
* compare two maps. Returns true if both maps have the same number of |
|---|
| 130 |
* elements, and both maps have elements whose keys and values are equal. |
|---|
| 131 |
* |
|---|
| 132 |
* If o is not a map, then 0 is returned. |
|---|
| 133 |
*/ |
|---|
| 134 |
bool opEquals(Object o); |
|---|
| 135 |
|
|---|
| 136 |
/** |
|---|
| 137 |
* compare map to an AA |
|---|
| 138 |
*/ |
|---|
| 139 |
bool opEquals(V[K] other); |
|---|
| 140 |
} |
|---|