29 #ifndef CDPL_UTIL_MULTIMAP_HPP
30 #define CDPL_UTIL_MULTIMAP_HPP
48 template <
typename ValueType,
bool Allow = true>
52 static const ValueType&
get()
60 template <
typename ValueType,
bool Allow>
63 template <
typename ValueType>
67 static const ValueType&
get()
93 template <
typename Key,
typename Value,
bool AllowDefValues =
false,
94 typename KeyCompFunc = std::less<Key> >
98 typedef std::multimap<Key, Value, KeyCompFunc> StorageType;
122 typedef typename StorageType::value_type
Entry;
172 template <
typename InputIter>
173 MultiMap(
const InputIter& first,
const InputIter& last):
184 template <
typename InputIter>
185 MultiMap(
const InputIter& first,
const InputIter& last,
const KeyCompFunc& func):
186 data(first, last, func)
355 const Value&
getValue(
const Key& key,
const Value& def_value)
const;
486 template <
typename InputIter>
499 template <
typename InputIter>
500 void setEntries(
const InputIter& first,
const InputIter& last);
633 const Value& getDefaultValue()
const;
646 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
658 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
670 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
682 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
694 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
706 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
716 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
717 typename CDPL::Util::MultiMap<Key, Value, AllowDefValues, KeyCompFunc>::StorageType&
723 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
724 const typename CDPL::Util::MultiMap<Key, Value, AllowDefValues, KeyCompFunc>::StorageType&
730 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
736 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
742 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
748 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
754 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
757 return data.key_comp();
760 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
763 return data.count(key);
766 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
770 return data.find(key);
773 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
777 return data.find(key);
780 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
784 return data.equal_range(key);
787 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
791 return data.equal_range(key);
794 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
799 if (lb == data.end() || data.key_comp()(key, (*lb).first)) {
803 return (*data.insert(lb,
Entry(key, getDefaultValue()))).second;
809 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
814 if (it == data.end())
820 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
825 if (it == data.end()) {
829 return getDefaultValue();
835 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
837 const Value& def_value)
const
841 if (it == data.end())
847 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
850 return getValue(key);
853 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
856 return getValue(key);
859 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
865 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
870 if (it == data.end())
877 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
880 return data.erase(key);
883 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
887 data.erase(first, last);
890 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
894 return data.insert(item);
897 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
901 return data.insert(
Entry(key, value));
904 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
908 return data.insert(it, item);
911 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
916 return data.insert(it,
Entry(key, value));
919 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
926 if (lb == end || data.key_comp()(item.first, (*lb).first))
927 return data.insert(lb, item);
931 while (range_end != end && !data.key_comp()(item.first, (*range_end).first))
934 data.erase(lb, range_end);
936 return data.insert(range_end, item);
939 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
943 return setEntry(
Entry(key, value));
946 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
947 template <
typename InputIter>
949 const InputIter& last)
951 data.insert(first, last);
954 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
955 template <
typename InputIter>
957 const InputIter& last)
959 for (InputIter it = first; it != last; ++it)
963 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
967 return data.lower_bound(key);
970 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
974 return data.lower_bound(key);
977 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
981 return data.upper_bound(key);
984 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
988 return data.upper_bound(key);
991 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
998 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1002 return data.begin();
1005 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1012 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1019 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1023 return data.begin();
1026 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1030 return data.begin();
1033 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1040 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1047 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1051 return data.rbegin();
1054 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1058 return data.rbegin();
1061 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1068 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1075 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1081 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1089 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1091 const MultiMap<Key, Value, AllowDefValues, KeyCompFunc>& map2)
1093 return (map1.getData() == map2.getData());
1096 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1098 const MultiMap<Key, Value, AllowDefValues, KeyCompFunc>& map2)
1100 return (map1.getData() != map2.getData());
1103 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1105 const MultiMap<Key, Value, AllowDefValues, KeyCompFunc>& map2)
1107 return (map1.getData() <= map2.getData());
1110 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1112 const MultiMap<Key, Value, AllowDefValues, KeyCompFunc>& map2)
1114 return (map1.getData() >= map2.getData());
1117 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1119 const MultiMap<Key, Value, AllowDefValues, KeyCompFunc>& map2)
1121 return (map1.getData() < map2.getData());
1124 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1126 const MultiMap<Key, Value, AllowDefValues, KeyCompFunc>& map2)
1128 return (map1.getData() > map2.getData());
Definition of exception classes.
Thrown to indicate that some requested data item could not be found.
Definition: Base/Exceptions.hpp:171
Thrown to indicate that some requested operation has failed (e.g. due to unfulfilled preconditions or...
Definition: Base/Exceptions.hpp:211
A multiple sorted associative container that maps keys to values.
Definition: MultiMap.hpp:96
Key KeyType
The type of the map's keys.
Definition: MultiMap.hpp:109
ConstEntryIterator getEntriesEnd() const
Returns a constant iterator pointing to the end of the map.
Definition: MultiMap.hpp:1007
void swap(MultiMap &map)
Swaps the contents with map.
Definition: MultiMap.hpp:749
EntryIterator insertEntry(const EntryIterator &it, const Entry &item)
Inserts the key/value pair item into the map and uses the iterator it as a hint for the insertion loc...
Definition: MultiMap.hpp:906
ConstReverseEntryIterator getEntriesReverseEnd() const
Returns a constant iterator pointing to the end of the reversed map.
Definition: MultiMap.hpp:1063
void removeEntries(const EntryIterator &first, const EntryIterator &last)
Removes all entries pointed to by the iterators in the range [first, last) from the map.
Definition: MultiMap.hpp:884
std::pair< EntryIterator, EntryIterator > EntryIteratorRange
A pair of mutable iterators used to specify the start and end of a range of entries.
Definition: MultiMap.hpp:147
virtual ~MultiMap()
Virtual destructor.
Definition: MultiMap.hpp:192
EntryIterator insertEntry(const Key &key, const Value &value)
Inserts a new entry with specified key and value into the map.
Definition: MultiMap.hpp:899
const Value & getValue(const Key &key) const
Returns a const reference to the first value associated with the specified key.
Definition: MultiMap.hpp:821
const Value & operator[](const Key &key) const
Returns a const reference to the first value associated with the specified key.
Definition: MultiMap.hpp:854
ConstEntryIterator getUpperBound(const Key &key) const
Returns a constant iterator pointing to the first entry whose key is greater than key.
Definition: MultiMap.hpp:986
EntryIterator setEntry(const Entry &item)
Replaces all entries with a key equivalent to that of item with a single entry specified by item.
Definition: MultiMap.hpp:921
const StorageType & getData() const
Returns a const reference to the underlying map storage.
Definition: MultiMap.hpp:725
StorageType::iterator EntryIterator
A mutable iterator used to iterate over the entries of the map.
Definition: MultiMap.hpp:137
void setEntries(const InputIter &first, const InputIter &last)
Inserts new entries or updates the value of existing entries using the key/value pairs in the range [...
Definition: MultiMap.hpp:956
EntryIterator getLowerBound(const Key &key)
Returns a mutable iterator pointing to the first entry whose key is not less than key.
Definition: MultiMap.hpp:965
std::size_t getNumEntries(const Key &key) const
Returns the number of entries with the specified key.
Definition: MultiMap.hpp:761
EntryIterator getUpperBound(const Key &key)
Returns a mutable iterator pointing to the first entry whose key is greater than key.
Definition: MultiMap.hpp:979
ConstReverseEntryIterator getEntriesReverseBegin() const
Returns a constant iterator pointing to the beginning of the reversed map.
Definition: MultiMap.hpp:1049
MultiMap(const InputIter &first, const InputIter &last)
Creates and initializes the map with copies of the key value pairs in the range [first,...
Definition: MultiMap.hpp:173
EntryIterator insertEntry(const EntryIterator &it, const Key &key, const Value &value)
Inserts a new entry with the specified key and value into the map and uses the iterator it as a hint ...
Definition: MultiMap.hpp:913
EntryIterator setEntry(const Key &key, const Value &value)
Replaces all entries with a key equivalent to key with a single copy of the key/value pair (key,...
Definition: MultiMap.hpp:941
Value & getValue(const Key &key)
Returns a non-const reference to the first value associated with the specified key.
Definition: MultiMap.hpp:795
EntryIterator insertEntry(const Entry &item)
Inserts the key/value pair item into the map.
Definition: MultiMap.hpp:892
void removeEntry(const EntryIterator &it)
Removes the entry pointed to by the iterator it from the map.
Definition: MultiMap.hpp:860
StorageType::value_type Entry
The type of the key/value pairs stored in the map.
Definition: MultiMap.hpp:122
ConstEntryIterator getEntry(const Key &key) const
Returns a constant iterator pointing to the first entry with the specified key.
Definition: MultiMap.hpp:775
EntryIterator end()
Returns a mutable iterator pointing to the end of the map.
Definition: MultiMap.hpp:1042
MultiMap(const KeyCompFunc &func)
Creates an empty map and uses func as key compare function.
Definition: MultiMap.hpp:164
MultiMap()
Creates an empty map.
Definition: MultiMap.hpp:157
Value ValueType
The type of the mapped values.
Definition: MultiMap.hpp:114
std::pair< ConstEntryIterator, ConstEntryIterator > ConstEntryIteratorRange
A pair of constant iterators used to specify the start and end of a range of entries.
Definition: MultiMap.hpp:152
Value & getValue(const Key &key, Value &def_value)
Returns a non-const reference to the first value associated with the specified key,...
Definition: MultiMap.hpp:810
void insertEntries(const InputIter &first, const InputIter &last)
Inserts the key/value pairs in the range [first, last) into the map.
Definition: MultiMap.hpp:948
std::size_t getSize() const
Returns the size (number of entries) of the map.
Definition: MultiMap.hpp:731
ReverseEntryIterator getEntriesReverseEnd()
Returns a mutable iterator pointing to the end of the reversed map.
Definition: MultiMap.hpp:1070
ReverseEntryIterator getEntriesReverseBegin()
Returns a mutable iterator pointing to the beginning of the reversed map.
Definition: MultiMap.hpp:1056
std::size_t removeEntries(const Key &key)
Removes all entries with the specified key from the map.
Definition: MultiMap.hpp:878
StorageType & getData()
Returns a non-const reference to the underlying map storage.
Definition: MultiMap.hpp:718
ConstEntryIteratorRange getEntries(const Key &key) const
Returns the bounds of a range that includes all entries with a key that compares equal to the specifi...
Definition: MultiMap.hpp:789
StorageType::const_reverse_iterator ConstReverseEntryIterator
A constant iterator used to iterate backwards over the entries of the map.
Definition: MultiMap.hpp:132
MultiMap(const InputIter &first, const InputIter &last, const KeyCompFunc &func)
Creates and initializes the map with copies of the key value pairs in the range [first,...
Definition: MultiMap.hpp:185
std::shared_ptr< MultiMap > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MultiMap instances.
Definition: MultiMap.hpp:104
bool removeEntry(const Key &key)
Removes the first entry with the specified key from the map.
Definition: MultiMap.hpp:866
ConstEntryIterator begin() const
Returns a constant iterator pointing to the beginning of the map.
Definition: MultiMap.hpp:1021
KeyCompFunc getKeyCompareFunction() const
Returns the key compare function used by the map.
Definition: MultiMap.hpp:755
EntryIteratorRange getEntries(const Key &key)
Returns the bounds of a range that includes all entries with a key that compares equal to the specifi...
Definition: MultiMap.hpp:782
virtual const char * getClassName() const
Returns the name of the (derived) Map class.
Definition: MultiMap.hpp:1076
bool isEmpty() const
Tells whether the map is empty (getSize() == 0).
Definition: MultiMap.hpp:737
ConstEntryIterator getEntriesBegin() const
Returns a constant iterator pointing to the beginning of the map.
Definition: MultiMap.hpp:993
EntryIterator begin()
Returns a mutable iterator pointing to the beginning of the map.
Definition: MultiMap.hpp:1028
StorageType::reverse_iterator ReverseEntryIterator
A mutable iterator used to iterate backwards over the entries of the map.
Definition: MultiMap.hpp:142
ConstEntryIterator getLowerBound(const Key &key) const
Returns a constant iterator pointing to the first entry whose key is not less than key.
Definition: MultiMap.hpp:972
Value & operator[](const Key &key)
Returns a non-const reference to the first value associated with the specified key.
Definition: MultiMap.hpp:848
EntryIterator getEntriesEnd()
Returns a mutable iterator pointing to the end of the map.
Definition: MultiMap.hpp:1014
const Value & getValue(const Key &key, const Value &def_value) const
Returns a const reference to the first value associated with the specified key, or the value given by...
Definition: MultiMap.hpp:836
ConstEntryIterator end() const
Returns a constant iterator pointing to the end of the map.
Definition: MultiMap.hpp:1035
StorageType::const_iterator ConstEntryIterator
A constant iterator used to iterate over the entries of the map.
Definition: MultiMap.hpp:127
void clear()
Erases all entries.
Definition: MultiMap.hpp:743
EntryIterator getEntry(const Key &key)
Returns a mutable iterator pointing to the first entry with the specified key.
Definition: MultiMap.hpp:768
EntryIterator getEntriesBegin()
Returns a mutable iterator pointing to the beginning of the map.
Definition: MultiMap.hpp:1000
bool operator<(const Array< ValueType > &array1, const Array< ValueType > &array2)
Less than comparison operator.
bool operator>=(const Array< ValueType > &array1, const Array< ValueType > &array2)
Greater or equal comparison operator.
bool operator>(const Array< ValueType > &array1, const Array< ValueType > &array2)
Greater than comparison operator.
bool operator!=(const Array< ValueType > &array1, const Array< ValueType > &array2)
Inequality comparison operator.
bool operator<=(const Array< ValueType > &array1, const Array< ValueType > &array2)
Less or equal comparison operator.
bool operator==(const Array< ValueType > &array1, const Array< ValueType > &array2)
Equality comparison operator.
The namespace of the Chemical Data Processing Library.
static const ValueType & get()
Definition: MultiMap.hpp:67
Definition: MultiMap.hpp:50
static const ValueType & get()
Definition: MultiMap.hpp:52
static const ValueType defValue
Definition: MultiMap.hpp:57