/usr/include/bobcat/linearmap is in libbobcat-dev 4.04.00-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | #ifndef INCLUDED_BOBCAT_LINEARMAP_
#define INCLUDED_BOBCAT_LINEARMAP_
#include <vector>
#include <algorithm>
#include <stdexcept>
#include <initializer_list>
namespace FBB
{
template <
typename Key, typename Value,
typename Alloc = std::allocator< std::pair<Key const, Value> >
>
class LinearMap: private std::vector<std::pair<Key, Value>, Alloc>
{
typedef std::vector<std::pair<Key, Value>, Alloc> Base;
typedef LinearMap<Key, Value, Alloc> LinMap;
typedef std::pair<
typename LinearMap<Key, Value, Alloc>::const_iterator,
typename LinearMap<Key, Value, Alloc>::const_iterator
> ConstIterPair;
typedef std::pair<
typename LinearMap<Key, Value, Alloc>::iterator,
typename LinearMap<Key, Value, Alloc>::iterator
> IterPair;
public:
typedef std::pair<Key, Value> value_type;
typedef typename Base::iterator iterator;
typedef typename Base::const_iterator const_iterator;
typedef typename Base::reverse_iterator reverse_iterator;
typedef typename Base::const_reverse_iterator const_reverse_iterator;
LinearMap() = default;
LinearMap(LinMap const &other) = default;
template <typename Iterator>
LinearMap(Iterator begin, Iterator end);
LinearMap(std::initializer_list<value_type> initial);
LinMap &operator=(LinMap const &other) = default;
Value &operator[](Key const &key);
Value &at(Key const &key);
using Base::begin;
using Base::capacity;
using Base::cbegin;
using Base::cend;
using Base::clear;
size_t count(Key const &key) const;
using Base::crbegin;
using Base::crend;
using Base::emplace;
using Base::empty;
using Base::end;
IterPair equal_range(Key const &key);
ConstIterPair equal_range(Key const &key) const;
bool erase(Key const &key);
void erase(iterator iter);
void erase(iterator begin, iterator end);
iterator find(Key const &key);
const_iterator find(Key const &key) const;
using Base::get_allocator;
std::pair<iterator, bool> insert(value_type const &keyvalue);
iterator insert(iterator pos, value_type const &keyValue);
template <typename Iterator>
void insert(Iterator begin, Iterator end);
iterator lower_bound(Key const &key);
const_iterator lower_bound(Key const &key) const;
using Base::max_size;
using Base::rbegin;
using Base::rend;
using Base::reserve;
using Base::size;
using Base::swap;
iterator upper_bound(Key const &key);
const_iterator upper_bound(Key const &key) const;
private:
value_type *findPtr(Key const &key) const;
};
// size_t count(Key const &key) const
template <typename Key, typename Value, typename Alloc>
inline size_t LinearMap<Key, Value, Alloc>::count(Key const &key) const
{
return find(key) != end();
}
// std::pair<iterator, iterator> equal_range(Key const &key)
template <typename Key, typename Value, typename Alloc>
inline typename LinearMap<Key, Value, Alloc>::IterPair
LinearMap<Key, Value, Alloc>::equal_range(Key const &key)
{
iterator iter = lower_bound(key);
return IterPair(iter, iter);
}
// bool erase(Key const &key)
//
template <typename Key, typename Value, typename Alloc>
bool LinearMap<Key, Value, Alloc>::erase(Key const &key)
{
auto iter = find(key);
if (iter == end())
return false;
erase(iter);
return true;
}
// bool erase(Key const &key)
//
template <typename Key, typename Value, typename Alloc>
void LinearMap<Key, Value, Alloc>::erase(iterator iter)
{
Base::erase(iter);
}
// bool erase(Key const &key)
//
template <typename Key, typename Value, typename Alloc>
void LinearMap<Key, Value, Alloc>::erase(iterator begin, iterator end)
{
Base::erase(begin, end);
}
// iterator find(Key const &key)
template <typename Key, typename Value, typename Alloc>
inline typename LinearMap<Key, Value, Alloc>::iterator
LinearMap<Key, Value, Alloc>:: find(Key const &key)
{
return iterator(findPtr(key));
}
// const_iterator find(Key const &key) const
template <typename Key, typename Value, typename Alloc>
inline typename LinearMap<Key, Value, Alloc>::const_iterator
LinearMap<Key, Value, Alloc>::find(Key const &key) const
{
return const_iterator(findPtr(key));
}
// value_type *findPtr(Key const &key) const
template <typename Key, typename Value, typename Alloc>
inline typename LinearMap<Key, Value, Alloc>::value_type *
LinearMap<Key, Value, Alloc>:: findPtr(Key const &key) const
{
value_type *ptr = const_cast<value_type *>(&*begin());
return std::find_if(ptr, ptr + size(),
[&](value_type const &value)
{
return key == value.first;
}
);
}
// pair<iterator, bool> insert(value_type const keyvalue);
template <typename Key, typename Value, typename Alloc>
std::pair<typename LinearMap<Key, Value, Alloc>::iterator, bool>
LinearMap<Key, Value, Alloc>::insert(value_type const &keyValue)
{
bool inserted;
auto iter = find(keyValue.first);
if (iter != end())
inserted = false;
else
{
Base::push_back(keyValue);
iter = iterator(&Base::back());
inserted = true;
}
return std::pair<iterator, bool>(iter, inserted);
}
// iterator insert(iterator pos, value_type const &keyValue);
template <typename Key, typename Value, typename Alloc>
typename LinearMap<Key, Value, Alloc>::iterator
LinearMap<Key, Value, Alloc>::insert(iterator pos,
value_type const &keyvalue)
{
auto iter = find(keyvalue.first);
if (iter == end())
{
push_back(keyvalue);
iter = iterator(&Base::back());
}
return iter;
}
// iterator insert(iterator pos, value_type const &keyValue);
template <typename Key, typename Value, typename Alloc>
template <typename Iterator>
inline void LinearMap<Key, Value, Alloc>::insert(Iterator begin, Iterator end)
{
for (; begin != end; ++begin)
insert(*begin);
}
// LinearMap(Iterator begin, Iterator end)
template <typename Key, typename Value, typename Alloc>
template <typename Iterator>
inline LinearMap<Key, Value, Alloc>::
LinearMap(Iterator begin, Iterator end)
{
insert(begin, end);
}
// LinearMap(initializer_list<value_type> initial)
template <typename Key, typename Value, typename Alloc>
inline LinearMap<Key, Value, Alloc>::
LinearMap(std::initializer_list<value_type> initial)
{
for (auto &value: initial)
insert(value);
}
// iterator lower_bound(Key const &key)
template <typename Key, typename Value, typename Alloc>
inline typename LinearMap<Key, Value, Alloc>::iterator
LinearMap<Key, Value, Alloc>:: lower_bound(Key const &key)
{
return iterator(findPtr(key));
}
// const_iterator lower_bound(Key const &key) const
template <typename Key, typename Value, typename Alloc>
inline typename LinearMap<Key, Value, Alloc>::const_iterator
LinearMap<Key, Value, Alloc>::lower_bound(Key const &key) const
{
return const_iterator(findPtr(key));
}
//Value &operator[])Key const &key)
template <typename Key, typename Value, typename Alloc>
Value &LinearMap<Key, Value, Alloc>::operator[](Key const &key)
{
auto iter = find(key);
if (iter != end())
return iter->second;
Base::push_back(value_type(key, Value()));
return Base::back().second;
}
// iterator upper_bound(Key const &key)
template <typename Key, typename Value, typename Alloc>
inline typename LinearMap<Key, Value, Alloc>::iterator
LinearMap<Key, Value, Alloc>:: upper_bound(Key const &key)
{
return iterator(findPtr(key));
}
// const_iterator upper_bound(Key const &key) const
template <typename Key, typename Value, typename Alloc>
inline typename LinearMap<Key, Value, Alloc>::const_iterator
LinearMap<Key, Value, Alloc>::upper_bound(Key const &key) const
{
return const_iterator(findPtr(key));
}
} // FBB
#endif
|