annotate DEPENDENCIES/generic/include/boost/numeric/ublas/storage_sparse.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // Copyright (c) 2000-2002
Chris@16 3 // Joerg Walter, Mathias Koch
Chris@16 4 //
Chris@16 5 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 6 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8 //
Chris@16 9 // The authors gratefully acknowledge the support of
Chris@16 10 // GeNeSys mbH & Co. KG in producing this work.
Chris@16 11 //
Chris@16 12
Chris@16 13 #ifndef _BOOST_UBLAS_STORAGE_SPARSE_
Chris@16 14 #define _BOOST_UBLAS_STORAGE_SPARSE_
Chris@16 15
Chris@16 16 #include <map>
Chris@16 17 #include <boost/serialization/collection_size_type.hpp>
Chris@16 18 #include <boost/serialization/nvp.hpp>
Chris@16 19 #include <boost/serialization/array.hpp>
Chris@16 20 #include <boost/serialization/map.hpp>
Chris@16 21 #include <boost/serialization/base_object.hpp>
Chris@16 22
Chris@16 23 #include <boost/numeric/ublas/storage.hpp>
Chris@16 24
Chris@16 25
Chris@16 26 namespace boost { namespace numeric { namespace ublas {
Chris@16 27
Chris@16 28 namespace detail {
Chris@16 29
Chris@16 30 template<class I, class T, class C>
Chris@16 31 BOOST_UBLAS_INLINE
Chris@16 32 I lower_bound (const I &begin, const I &end, const T &t, C compare) {
Chris@16 33 // t <= *begin <=> ! (*begin < t)
Chris@16 34 if (begin == end || ! compare (*begin, t))
Chris@16 35 return begin;
Chris@16 36 if (compare (*(end - 1), t))
Chris@16 37 return end;
Chris@16 38 return std::lower_bound (begin, end, t, compare);
Chris@16 39 }
Chris@16 40 template<class I, class T, class C>
Chris@16 41 BOOST_UBLAS_INLINE
Chris@16 42 I upper_bound (const I &begin, const I &end, const T &t, C compare) {
Chris@16 43 if (begin == end || compare (t, *begin))
Chris@16 44 return begin;
Chris@16 45 // (*end - 1) <= t <=> ! (t < *end)
Chris@16 46 if (! compare (t, *(end - 1)))
Chris@16 47 return end;
Chris@16 48 return std::upper_bound (begin, end, t, compare);
Chris@16 49 }
Chris@16 50
Chris@16 51 template<class P>
Chris@16 52 struct less_pair {
Chris@16 53 BOOST_UBLAS_INLINE
Chris@16 54 bool operator () (const P &p1, const P &p2) {
Chris@16 55 return p1.first < p2.first;
Chris@16 56 }
Chris@16 57 };
Chris@16 58 template<class T>
Chris@16 59 struct less_triple {
Chris@16 60 BOOST_UBLAS_INLINE
Chris@16 61 bool operator () (const T &t1, const T &t2) {
Chris@16 62 return t1.first.first < t2.first.first ||
Chris@16 63 (t1.first.first == t2.first.first && t1.first.second < t2.first.second);
Chris@16 64 }
Chris@16 65 };
Chris@16 66
Chris@16 67 }
Chris@16 68
Chris@16 69 #ifdef BOOST_UBLAS_STRICT_MAP_ARRAY
Chris@16 70 template<class A>
Chris@16 71 class sparse_storage_element:
Chris@16 72 public container_reference<A> {
Chris@16 73 public:
Chris@16 74 typedef A array_type;
Chris@16 75 typedef typename A::key_type index_type;
Chris@16 76 typedef typename A::mapped_type data_value_type;
Chris@16 77 // typedef const data_value_type &data_const_reference;
Chris@16 78 typedef typename type_traits<data_value_type>::const_reference data_const_reference;
Chris@16 79 typedef data_value_type &data_reference;
Chris@16 80 typedef typename A::value_type value_type;
Chris@16 81 typedef value_type *pointer;
Chris@16 82
Chris@16 83 // Construction and destruction
Chris@16 84 BOOST_UBLAS_INLINE
Chris@16 85 sparse_storage_element (array_type &a, pointer it):
Chris@16 86 container_reference<array_type> (a), it_ (it), i_ (it->first), d_ (it->second), dirty_ (false) {}
Chris@16 87 BOOST_UBLAS_INLINE
Chris@16 88 sparse_storage_element (array_type &a, index_type i):
Chris@16 89 container_reference<array_type> (a), it_ (), i_ (i), d_ (), dirty_ (false) {
Chris@16 90 pointer it = (*this) ().find (i_);
Chris@16 91 if (it == (*this) ().end ())
Chris@16 92 it = (*this) ().insert ((*this) ().end (), value_type (i_, d_));
Chris@16 93 d_ = it->second;
Chris@16 94 }
Chris@16 95 BOOST_UBLAS_INLINE
Chris@16 96 ~sparse_storage_element () {
Chris@16 97 if (dirty_) {
Chris@16 98 if (! it_)
Chris@16 99 it_ = (*this) ().find (i_);
Chris@16 100 BOOST_UBLAS_CHECK (it_ != (*this) ().end (), internal_logic ());
Chris@16 101 it_->second = d_;
Chris@16 102 }
Chris@16 103 }
Chris@16 104
Chris@16 105 // Element access - only if data_const_reference is defined
Chris@16 106 BOOST_UBLAS_INLINE
Chris@16 107 typename data_value_type::data_const_reference
Chris@16 108 operator [] (index_type i) const {
Chris@16 109 return d_ [i];
Chris@16 110 }
Chris@16 111
Chris@16 112 // Assignment
Chris@16 113 BOOST_UBLAS_INLINE
Chris@16 114 sparse_storage_element &operator = (const sparse_storage_element &p) {
Chris@16 115 // Overide the implict copy assignment
Chris@16 116 d_ = p.d_;
Chris@16 117 dirty_ = true;
Chris@16 118 return *this;
Chris@16 119 }
Chris@16 120 template<class D>
Chris@16 121 BOOST_UBLAS_INLINE
Chris@16 122 sparse_storage_element &operator = (const D &d) {
Chris@16 123 d_ = d;
Chris@16 124 dirty_ = true;
Chris@16 125 return *this;
Chris@16 126 }
Chris@16 127 template<class D>
Chris@16 128 BOOST_UBLAS_INLINE
Chris@16 129 sparse_storage_element &operator += (const D &d) {
Chris@16 130 d_ += d;
Chris@16 131 dirty_ = true;
Chris@16 132 return *this;
Chris@16 133 }
Chris@16 134 template<class D>
Chris@16 135 BOOST_UBLAS_INLINE
Chris@16 136 sparse_storage_element &operator -= (const D &d) {
Chris@16 137 d_ -= d;
Chris@16 138 dirty_ = true;
Chris@16 139 return *this;
Chris@16 140 }
Chris@16 141 template<class D>
Chris@16 142 BOOST_UBLAS_INLINE
Chris@16 143 sparse_storage_element &operator *= (const D &d) {
Chris@16 144 d_ *= d;
Chris@16 145 dirty_ = true;
Chris@16 146 return *this;
Chris@16 147 }
Chris@16 148 template<class D>
Chris@16 149 BOOST_UBLAS_INLINE
Chris@16 150 sparse_storage_element &operator /= (const D &d) {
Chris@16 151 d_ /= d;
Chris@16 152 dirty_ = true;
Chris@16 153 return *this;
Chris@16 154 }
Chris@16 155
Chris@16 156 // Comparison
Chris@16 157 template<class D>
Chris@16 158 BOOST_UBLAS_INLINE
Chris@16 159 bool operator == (const D &d) const {
Chris@16 160 return d_ == d;
Chris@16 161 }
Chris@16 162 template<class D>
Chris@16 163 BOOST_UBLAS_INLINE
Chris@16 164 bool operator != (const D &d) const {
Chris@16 165 return d_ != d;
Chris@16 166 }
Chris@16 167
Chris@16 168 // Conversion
Chris@16 169 BOOST_UBLAS_INLINE
Chris@16 170 operator data_const_reference () const {
Chris@16 171 return d_;
Chris@16 172 }
Chris@16 173
Chris@16 174 // Swapping
Chris@16 175 BOOST_UBLAS_INLINE
Chris@16 176 void swap (sparse_storage_element p) {
Chris@16 177 if (this != &p) {
Chris@16 178 dirty_ = true;
Chris@16 179 p.dirty_ = true;
Chris@16 180 std::swap (d_, p.d_);
Chris@16 181 }
Chris@16 182 }
Chris@16 183 BOOST_UBLAS_INLINE
Chris@16 184 friend void swap (sparse_storage_element p1, sparse_storage_element p2) {
Chris@16 185 p1.swap (p2);
Chris@16 186 }
Chris@16 187
Chris@16 188 private:
Chris@16 189 pointer it_;
Chris@16 190 index_type i_;
Chris@16 191 data_value_type d_;
Chris@16 192 bool dirty_;
Chris@16 193 };
Chris@16 194 #endif
Chris@16 195
Chris@16 196
Chris@16 197 // Default map type is simply forwarded to std::map
Chris@16 198 // FIXME should use ALLOC for map but std::allocator of std::pair<const I, T> and std::pair<I,T> fail to compile
Chris@16 199 template<class I, class T, class ALLOC>
Chris@16 200 class map_std : public std::map<I, T /*, ALLOC */> {
Chris@16 201 public:
Chris@16 202 // Serialization
Chris@16 203 template<class Archive>
Chris@16 204 void serialize(Archive & ar, const unsigned int /* file_version */){
Chris@16 205 ar & serialization::make_nvp("base", boost::serialization::base_object< std::map<I, T /*, ALLOC */> >(*this));
Chris@16 206 }
Chris@16 207 };
Chris@16 208
Chris@16 209
Chris@16 210
Chris@16 211
Chris@16 212 // Map array
Chris@16 213 // Implementation requires pair<I, T> allocator definition (without const)
Chris@16 214 template<class I, class T, class ALLOC>
Chris@16 215 class map_array {
Chris@16 216 public:
Chris@16 217 typedef ALLOC allocator_type;
Chris@16 218 typedef typename ALLOC::size_type size_type;
Chris@16 219 typedef typename ALLOC::difference_type difference_type;
Chris@16 220 typedef std::pair<I,T> value_type;
Chris@16 221 typedef I key_type;
Chris@16 222 typedef T mapped_type;
Chris@16 223 typedef const value_type &const_reference;
Chris@16 224 typedef value_type &reference;
Chris@16 225 typedef const value_type *const_pointer;
Chris@16 226 typedef value_type *pointer;
Chris@16 227 // Iterators simply are pointers.
Chris@16 228 typedef const_pointer const_iterator;
Chris@16 229 typedef pointer iterator;
Chris@16 230
Chris@16 231 typedef const T &data_const_reference;
Chris@16 232 #ifndef BOOST_UBLAS_STRICT_MAP_ARRAY
Chris@16 233 typedef T &data_reference;
Chris@16 234 #else
Chris@16 235 typedef sparse_storage_element<map_array> data_reference;
Chris@16 236 #endif
Chris@16 237
Chris@16 238 // Construction and destruction
Chris@16 239 BOOST_UBLAS_INLINE
Chris@16 240 map_array (const ALLOC &a = ALLOC()):
Chris@16 241 alloc_(a), capacity_ (0), size_ (0) {
Chris@16 242 data_ = 0;
Chris@16 243 }
Chris@16 244 BOOST_UBLAS_INLINE
Chris@16 245 map_array (const map_array &c):
Chris@16 246 alloc_ (c.alloc_), capacity_ (c.size_), size_ (c.size_) {
Chris@16 247 if (capacity_) {
Chris@16 248 data_ = alloc_.allocate (capacity_);
Chris@16 249 std::uninitialized_copy (data_, data_ + capacity_, c.data_);
Chris@16 250 // capacity != size_ requires uninitialized_fill (size_ to capacity_)
Chris@16 251 }
Chris@16 252 else
Chris@16 253 data_ = 0;
Chris@16 254 }
Chris@16 255 BOOST_UBLAS_INLINE
Chris@16 256 ~map_array () {
Chris@16 257 if (capacity_) {
Chris@16 258 std::for_each (data_, data_ + capacity_, static_destroy);
Chris@16 259 alloc_.deallocate (data_, capacity_);
Chris@16 260 }
Chris@16 261 }
Chris@16 262
Chris@16 263 private:
Chris@16 264 // Resizing - implicitly exposses uninitialized (but default constructed) mapped_type
Chris@16 265 BOOST_UBLAS_INLINE
Chris@16 266 void resize (size_type size) {
Chris@16 267 BOOST_UBLAS_CHECK (size_ <= capacity_, internal_logic ());
Chris@16 268 if (size > capacity_) {
Chris@16 269 const size_type capacity = size << 1;
Chris@16 270 BOOST_UBLAS_CHECK (capacity, internal_logic ());
Chris@16 271 pointer data = alloc_.allocate (capacity);
Chris@16 272 std::uninitialized_copy (data_, data_ + (std::min) (size, size_), data);
Chris@16 273 std::uninitialized_fill (data + (std::min) (size, size_), data + capacity, value_type ());
Chris@16 274
Chris@16 275 if (capacity_) {
Chris@16 276 std::for_each (data_, data_ + capacity_, static_destroy);
Chris@16 277 alloc_.deallocate (data_, capacity_);
Chris@16 278 }
Chris@16 279 capacity_ = capacity;
Chris@16 280 data_ = data;
Chris@16 281 }
Chris@16 282 size_ = size;
Chris@16 283 BOOST_UBLAS_CHECK (size_ <= capacity_, internal_logic ());
Chris@16 284 }
Chris@16 285 public:
Chris@16 286
Chris@16 287 // Reserving
Chris@16 288 BOOST_UBLAS_INLINE
Chris@16 289 void reserve (size_type capacity) {
Chris@16 290 BOOST_UBLAS_CHECK (size_ <= capacity_, internal_logic ());
Chris@16 291 // Reduce capacity_ if size_ allows
Chris@16 292 BOOST_UBLAS_CHECK (capacity >= size_, bad_size ());
Chris@16 293 pointer data;
Chris@16 294 if (capacity) {
Chris@16 295 data = alloc_.allocate (capacity);
Chris@16 296 std::uninitialized_copy (data_, data_ + size_, data);
Chris@16 297 std::uninitialized_fill (data + size_, data + capacity, value_type ());
Chris@16 298 }
Chris@16 299 else
Chris@16 300 data = 0;
Chris@16 301
Chris@16 302 if (capacity_) {
Chris@16 303 std::for_each (data_, data_ + capacity_, static_destroy);
Chris@16 304 alloc_.deallocate (data_, capacity_);
Chris@16 305 }
Chris@16 306 capacity_ = capacity;
Chris@16 307 data_ = data;
Chris@16 308 BOOST_UBLAS_CHECK (size_ <= capacity_, internal_logic ());
Chris@16 309 }
Chris@16 310
Chris@16 311 // Random Access Container
Chris@16 312 BOOST_UBLAS_INLINE
Chris@16 313 size_type size () const {
Chris@16 314 return size_;
Chris@16 315 }
Chris@16 316 BOOST_UBLAS_INLINE
Chris@16 317 size_type capacity () const {
Chris@16 318 return capacity_;
Chris@16 319 }
Chris@16 320 BOOST_UBLAS_INLINE
Chris@16 321 size_type max_size () const {
Chris@16 322 return 0; //TODO
Chris@16 323 }
Chris@16 324
Chris@16 325 BOOST_UBLAS_INLINE
Chris@16 326 bool empty () const {
Chris@16 327 return size_ == 0;
Chris@16 328 }
Chris@16 329
Chris@16 330 // Element access
Chris@16 331 BOOST_UBLAS_INLINE
Chris@16 332 data_reference operator [] (key_type i) {
Chris@16 333 #ifndef BOOST_UBLAS_STRICT_MAP_ARRAY
Chris@16 334 pointer it = find (i);
Chris@16 335 if (it == end ())
Chris@16 336 it = insert (end (), value_type (i, mapped_type (0)));
Chris@16 337 BOOST_UBLAS_CHECK (it != end (), internal_logic ());
Chris@16 338 return it->second;
Chris@16 339 #else
Chris@16 340 return data_reference (*this, i);
Chris@16 341 #endif
Chris@16 342 }
Chris@16 343
Chris@16 344 // Assignment
Chris@16 345 BOOST_UBLAS_INLINE
Chris@16 346 map_array &operator = (const map_array &a) {
Chris@16 347 if (this != &a) {
Chris@16 348 resize (a.size_);
Chris@16 349 std::copy (a.data_, a.data_ + a.size_, data_);
Chris@16 350 }
Chris@16 351 return *this;
Chris@16 352 }
Chris@16 353 BOOST_UBLAS_INLINE
Chris@16 354 map_array &assign_temporary (map_array &a) {
Chris@16 355 swap (a);
Chris@16 356 return *this;
Chris@16 357 }
Chris@16 358
Chris@16 359 // Swapping
Chris@16 360 BOOST_UBLAS_INLINE
Chris@16 361 void swap (map_array &a) {
Chris@16 362 if (this != &a) {
Chris@16 363 std::swap (capacity_, a.capacity_);
Chris@16 364 std::swap (data_, a.data_);
Chris@16 365 std::swap (size_, a.size_);
Chris@16 366 }
Chris@16 367 }
Chris@16 368 BOOST_UBLAS_INLINE
Chris@16 369 friend void swap (map_array &a1, map_array &a2) {
Chris@16 370 a1.swap (a2);
Chris@16 371 }
Chris@16 372
Chris@16 373 // Element insertion and deletion
Chris@16 374
Chris@16 375 // From Back Insertion Sequence concept
Chris@16 376 // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
Chris@16 377 iterator push_back (iterator it, const value_type &p) {
Chris@16 378 if (size () == 0 || (it = end () - 1)->first < p.first) {
Chris@16 379 resize (size () + 1);
Chris@16 380 *(it = end () - 1) = p;
Chris@16 381 return it;
Chris@16 382 }
Chris@16 383 external_logic ().raise ();
Chris@16 384 return it;
Chris@16 385 }
Chris@16 386 // Form Unique Associative Container concept
Chris@16 387 // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
Chris@16 388 std::pair<iterator,bool> insert (const value_type &p) {
Chris@16 389 iterator it = detail::lower_bound (begin (), end (), p, detail::less_pair<value_type> ());
Chris@16 390 if (it != end () && it->first == p.first)
Chris@16 391 return std::make_pair (it, false);
Chris@16 392 difference_type n = it - begin ();
Chris@16 393 resize (size () + 1);
Chris@16 394 it = begin () + n; // allow for invalidation
Chris@16 395 std::copy_backward (it, end () - 1, end ());
Chris@16 396 *it = p;
Chris@16 397 return std::make_pair (it, true);
Chris@16 398 }
Chris@16 399 // Form Sorted Associative Container concept
Chris@16 400 // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
Chris@16 401 iterator insert (iterator hint, const value_type &p) {
Chris@16 402 return insert (p).first;
Chris@16 403 }
Chris@16 404 // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
Chris@16 405 void erase (iterator it) {
Chris@16 406 BOOST_UBLAS_CHECK (begin () <= it && it < end (), bad_index ());
Chris@16 407 std::copy (it + 1, end (), it);
Chris@16 408 resize (size () - 1);
Chris@16 409 }
Chris@16 410 // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
Chris@16 411 void erase (iterator it1, iterator it2) {
Chris@16 412 if (it1 == it2) return /* nothing to erase */;
Chris@16 413 BOOST_UBLAS_CHECK (begin () <= it1 && it1 < it2 && it2 <= end (), bad_index ());
Chris@16 414 std::copy (it2, end (), it1);
Chris@16 415 resize (size () - (it2 - it1));
Chris@16 416 }
Chris@16 417 // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
Chris@16 418 void clear () {
Chris@16 419 resize (0);
Chris@16 420 }
Chris@16 421
Chris@16 422 // Element lookup
Chris@16 423 // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
Chris@16 424 const_iterator find (key_type i) const {
Chris@16 425 const_iterator it (detail::lower_bound (begin (), end (), value_type (i, mapped_type (0)), detail::less_pair<value_type> ()));
Chris@16 426 if (it == end () || it->first != i)
Chris@16 427 it = end ();
Chris@16 428 return it;
Chris@16 429 }
Chris@16 430 // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
Chris@16 431 iterator find (key_type i) {
Chris@16 432 iterator it (detail::lower_bound (begin (), end (), value_type (i, mapped_type (0)), detail::less_pair<value_type> ()));
Chris@16 433 if (it == end () || it->first != i)
Chris@16 434 it = end ();
Chris@16 435 return it;
Chris@16 436 }
Chris@16 437 // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
Chris@16 438 const_iterator lower_bound (key_type i) const {
Chris@16 439 return detail::lower_bound (begin (), end (), value_type (i, mapped_type (0)), detail::less_pair<value_type> ());
Chris@16 440 }
Chris@16 441 // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
Chris@16 442 iterator lower_bound (key_type i) {
Chris@16 443 return detail::lower_bound (begin (), end (), value_type (i, mapped_type (0)), detail::less_pair<value_type> ());
Chris@16 444 }
Chris@16 445
Chris@16 446 BOOST_UBLAS_INLINE
Chris@16 447 const_iterator begin () const {
Chris@16 448 return data_;
Chris@16 449 }
Chris@16 450 BOOST_UBLAS_INLINE
Chris@101 451 const_iterator cbegin () const {
Chris@101 452 return begin ();
Chris@101 453 }
Chris@101 454 BOOST_UBLAS_INLINE
Chris@16 455 const_iterator end () const {
Chris@16 456 return data_ + size_;
Chris@16 457 }
Chris@101 458 BOOST_UBLAS_INLINE
Chris@101 459 const_iterator cend () const {
Chris@101 460 return end ();
Chris@101 461 }
Chris@16 462
Chris@16 463 BOOST_UBLAS_INLINE
Chris@16 464 iterator begin () {
Chris@16 465 return data_;
Chris@16 466 }
Chris@16 467 BOOST_UBLAS_INLINE
Chris@16 468 iterator end () {
Chris@16 469 return data_ + size_;
Chris@16 470 }
Chris@16 471
Chris@16 472 // Reverse iterators
Chris@16 473 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Chris@16 474 typedef std::reverse_iterator<iterator> reverse_iterator;
Chris@16 475
Chris@16 476 BOOST_UBLAS_INLINE
Chris@16 477 const_reverse_iterator rbegin () const {
Chris@16 478 return const_reverse_iterator (end ());
Chris@16 479 }
Chris@16 480 BOOST_UBLAS_INLINE
Chris@101 481 const_reverse_iterator crbegin () const {
Chris@101 482 return rbegin ();
Chris@101 483 }
Chris@101 484 BOOST_UBLAS_INLINE
Chris@16 485 const_reverse_iterator rend () const {
Chris@16 486 return const_reverse_iterator (begin ());
Chris@16 487 }
Chris@16 488 BOOST_UBLAS_INLINE
Chris@101 489 const_reverse_iterator crend () const {
Chris@101 490 return rend ();
Chris@101 491 }
Chris@101 492
Chris@101 493 BOOST_UBLAS_INLINE
Chris@16 494 reverse_iterator rbegin () {
Chris@16 495 return reverse_iterator (end ());
Chris@16 496 }
Chris@16 497 BOOST_UBLAS_INLINE
Chris@16 498 reverse_iterator rend () {
Chris@16 499 return reverse_iterator (begin ());
Chris@16 500 }
Chris@16 501
Chris@16 502 // Allocator
Chris@16 503 allocator_type get_allocator () {
Chris@16 504 return alloc_;
Chris@16 505 }
Chris@16 506
Chris@16 507 // Serialization
Chris@16 508 template<class Archive>
Chris@16 509 void serialize(Archive & ar, const unsigned int /* file_version */){
Chris@16 510 serialization::collection_size_type s (size_);
Chris@16 511 ar & serialization::make_nvp("size",s);
Chris@16 512 if (Archive::is_loading::value) {
Chris@16 513 resize(s);
Chris@16 514 }
Chris@16 515 ar & serialization::make_array(data_, s);
Chris@16 516 }
Chris@16 517
Chris@16 518 private:
Chris@16 519 // Provide destroy as a non member function
Chris@16 520 BOOST_UBLAS_INLINE
Chris@16 521 static void static_destroy (reference p) {
Chris@16 522 (&p) -> ~value_type ();
Chris@16 523 }
Chris@16 524 ALLOC alloc_;
Chris@16 525 size_type capacity_;
Chris@16 526 pointer data_;
Chris@16 527 size_type size_;
Chris@16 528 };
Chris@16 529
Chris@16 530
Chris@16 531 namespace detail {
Chris@16 532 template<class A, class T>
Chris@16 533 struct map_traits {
Chris@16 534 typedef typename A::mapped_type &reference;
Chris@16 535 };
Chris@16 536 template<class I, class T, class ALLOC>
Chris@16 537 struct map_traits<map_array<I, T, ALLOC>, T > {
Chris@16 538 typedef typename map_array<I, T, ALLOC>::data_reference reference;
Chris@16 539 };
Chris@16 540
Chris@16 541 // reserve helpers for map_array and generic maps
Chris@16 542 // ISSUE should be in map_traits but want to use on all compilers
Chris@16 543
Chris@16 544 template<class M>
Chris@16 545 BOOST_UBLAS_INLINE
Chris@16 546 void map_reserve (M &/* m */, typename M::size_type /* capacity */) {
Chris@16 547 }
Chris@16 548 template<class I, class T, class ALLOC>
Chris@16 549 BOOST_UBLAS_INLINE
Chris@16 550 void map_reserve (map_array<I, T, ALLOC> &m, typename map_array<I, T, ALLOC>::size_type capacity) {
Chris@16 551 m.reserve (capacity);
Chris@16 552 }
Chris@16 553
Chris@16 554 template<class M>
Chris@16 555 struct map_capacity_traits {
Chris@16 556 typedef typename M::size_type type ;
Chris@16 557 type operator() ( M const& m ) const {
Chris@16 558 return m.size ();
Chris@16 559 }
Chris@16 560 } ;
Chris@16 561
Chris@16 562 template<class I, class T, class ALLOC>
Chris@16 563 struct map_capacity_traits< map_array<I, T, ALLOC> > {
Chris@16 564 typedef typename map_array<I, T, ALLOC>::size_type type ;
Chris@16 565 type operator() ( map_array<I, T, ALLOC> const& m ) const {
Chris@16 566 return m.capacity ();
Chris@16 567 }
Chris@16 568 } ;
Chris@16 569
Chris@16 570 template<class M>
Chris@16 571 BOOST_UBLAS_INLINE
Chris@16 572 typename map_capacity_traits<M>::type map_capacity (M const& m) {
Chris@16 573 return map_capacity_traits<M>() ( m );
Chris@16 574 }
Chris@16 575 }
Chris@16 576
Chris@16 577 }}}
Chris@16 578
Chris@16 579 #endif