1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825 |
- #ifndef UTIL_GTL_SPARSETABLE_H_
- #define UTIL_GTL_SPARSETABLE_H_
- #include "internal/sparseconfig.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #ifdef HAVE_STDINT_H
- #include <stdint.h>
- #endif
- #ifdef HAVE_SYS_TYPES_H
- #include <sys/types.h>
- #endif
- #ifdef HAVE_INTTYPES_H
- #include <inttypes.h>
- #endif
- #include <assert.h>
- #include <iterator>
- #include <algorithm>
- #include <memory>
- #include <vector>
- #include "type_traits.h"
- #include "internal/hashtable-common.h"
- #include "internal/libc_allocator_with_realloc.h"
- #ifndef HAVE_U_INT16_T
- # if defined HAVE_UINT16_T
- typedef uint16_t u_int16_t;
- # elif defined HAVE___UINT16
- typedef __int16 int16_t;
- typedef unsigned __int16 u_int16_t;
- # else
-
- typedef short int int16_t;
- typedef unsigned short int u_int16_t;
- # endif
- #endif
- _START_GOOGLE_NAMESPACE_
- namespace base {
- using GOOGLE_NAMESPACE::true_type;
- using GOOGLE_NAMESPACE::false_type;
- using GOOGLE_NAMESPACE::integral_constant;
- using GOOGLE_NAMESPACE::has_trivial_copy;
- using GOOGLE_NAMESPACE::has_trivial_destructor;
- using GOOGLE_NAMESPACE::is_same;
- }
- static const u_int16_t DEFAULT_SPARSEGROUP_SIZE = 48;
- template <class tabletype>
- class table_element_adaptor {
- public:
- typedef typename tabletype::value_type value_type;
- typedef typename tabletype::size_type size_type;
- typedef typename tabletype::reference reference;
- typedef typename tabletype::pointer pointer;
- table_element_adaptor(tabletype *tbl, size_type p)
- : table(tbl), pos(p) { }
- table_element_adaptor& operator= (const value_type &val) {
- table->set(pos, val);
- return *this;
- }
- operator value_type() { return table->get(pos); }
- pointer operator& () { return &table->mutating_get(pos); }
- private:
- tabletype* table;
- size_type pos;
- };
- template <class tabletype>
- class table_iterator {
- public:
- typedef table_iterator iterator;
- typedef std::random_access_iterator_tag iterator_category;
- typedef typename tabletype::value_type value_type;
- typedef typename tabletype::difference_type difference_type;
- typedef typename tabletype::size_type size_type;
- typedef table_element_adaptor<tabletype> reference;
- typedef table_element_adaptor<tabletype>* pointer;
-
- table_iterator(tabletype *tbl, size_type p)
- : table(tbl), pos(p) { }
-
- table_iterator() : table(NULL), pos(0) { }
-
-
-
-
-
-
- reference operator*() {
- return table_element_adaptor<tabletype>(table, pos);
- }
- pointer operator->() { return &(operator*()); }
-
- void check() const {
- assert(table);
- assert(pos <= table->size());
- }
-
-
- iterator& operator+=(size_type t) { pos += t; check(); return *this; }
- iterator& operator-=(size_type t) { pos -= t; check(); return *this; }
- iterator& operator++() { ++pos; check(); return *this; }
- iterator& operator--() { --pos; check(); return *this; }
- iterator operator++(int) { iterator tmp(*this);
- ++pos; check(); return tmp; }
- iterator operator--(int) { iterator tmp(*this);
- --pos; check(); return tmp; }
- iterator operator+(difference_type i) const { iterator tmp(*this);
- tmp += i; return tmp; }
- iterator operator-(difference_type i) const { iterator tmp(*this);
- tmp -= i; return tmp; }
- difference_type operator-(iterator it) const {
- assert(table == it.table);
- return pos - it.pos;
- }
- reference operator[](difference_type n) const {
- return *(*this + n);
- }
-
- bool operator==(const iterator& it) const {
- return table == it.table && pos == it.pos;
- }
- bool operator<(const iterator& it) const {
- assert(table == it.table);
- return pos < it.pos;
- }
- bool operator!=(const iterator& it) const { return !(*this == it); }
- bool operator<=(const iterator& it) const { return !(it < *this); }
- bool operator>(const iterator& it) const { return it < *this; }
- bool operator>=(const iterator& it) const { return !(*this < it); }
-
- tabletype *table;
- size_type pos;
- };
- template<class T>
- table_iterator<T> operator+(typename table_iterator<T>::difference_type i,
- table_iterator<T> it) {
- return it + i;
- }
- template <class tabletype>
- class const_table_iterator {
- public:
- typedef table_iterator<tabletype> iterator;
- typedef const_table_iterator const_iterator;
- typedef std::random_access_iterator_tag iterator_category;
- typedef typename tabletype::value_type value_type;
- typedef typename tabletype::difference_type difference_type;
- typedef typename tabletype::size_type size_type;
- typedef typename tabletype::const_reference reference;
- typedef typename tabletype::const_pointer pointer;
-
- const_table_iterator(const tabletype *tbl, size_type p)
- : table(tbl), pos(p) { }
-
- const_table_iterator() : table(NULL), pos(0) { }
-
-
- const_table_iterator(const iterator &from)
- : table(from.table), pos(from.pos) { }
-
-
-
-
- reference operator*() const { return (*table)[pos]; }
- pointer operator->() const { return &(operator*()); }
-
- void check() const {
- assert(table);
- assert(pos <= table->size());
- }
-
-
- const_iterator& operator+=(size_type t) { pos += t; check(); return *this; }
- const_iterator& operator-=(size_type t) { pos -= t; check(); return *this; }
- const_iterator& operator++() { ++pos; check(); return *this; }
- const_iterator& operator--() { --pos; check(); return *this; }
- const_iterator operator++(int) { const_iterator tmp(*this);
- ++pos; check(); return tmp; }
- const_iterator operator--(int) { const_iterator tmp(*this);
- --pos; check(); return tmp; }
- const_iterator operator+(difference_type i) const { const_iterator tmp(*this);
- tmp += i; return tmp; }
- const_iterator operator-(difference_type i) const { const_iterator tmp(*this);
- tmp -= i; return tmp; }
- difference_type operator-(const_iterator it) const {
- assert(table == it.table);
- return pos - it.pos;
- }
- reference operator[](difference_type n) const {
- return *(*this + n);
- }
-
- bool operator==(const const_iterator& it) const {
- return table == it.table && pos == it.pos;
- }
- bool operator<(const const_iterator& it) const {
- assert(table == it.table);
- return pos < it.pos;
- }
- bool operator!=(const const_iterator& it) const { return !(*this == it); }
- bool operator<=(const const_iterator& it) const { return !(it < *this); }
- bool operator>(const const_iterator& it) const { return it < *this; }
- bool operator>=(const const_iterator& it) const { return !(*this < it); }
-
- const tabletype *table;
- size_type pos;
- };
- template<class T>
- const_table_iterator<T> operator+(typename
- const_table_iterator<T>::difference_type i,
- const_table_iterator<T> it) {
- return it + i;
- }
- #define TWOD_BEGIN_ nonempty_begin
- #define TWOD_END_ nonempty_end
- #define TWOD_ITER_ nonempty_iterator
- #define TWOD_CONST_ITER_ const_nonempty_iterator
- template <class containertype>
- class two_d_iterator {
- public:
- typedef two_d_iterator iterator;
- typedef std::bidirectional_iterator_tag iterator_category;
-
- typedef typename containertype::value_type _tmp_vt;
- typedef typename _tmp_vt::value_type value_type;
- typedef typename _tmp_vt::difference_type difference_type;
- typedef typename _tmp_vt::reference reference;
- typedef typename _tmp_vt::pointer pointer;
-
-
- two_d_iterator(typename containertype::iterator begin,
- typename containertype::iterator end,
- typename containertype::iterator curr)
- : row_begin(begin), row_end(end), row_current(curr), col_current() {
- if ( row_current != row_end ) {
- col_current = row_current->TWOD_BEGIN_();
- advance_past_end();
- }
- }
-
- two_d_iterator(typename containertype::iterator begin,
- typename containertype::iterator end,
- typename containertype::iterator curr,
- typename containertype::value_type::TWOD_ITER_ col)
- : row_begin(begin), row_end(end), row_current(curr), col_current(col) {
- advance_past_end();
- }
-
- two_d_iterator() : row_begin(), row_end(), row_current(), col_current() { }
-
-
-
- reference operator*() const { return *col_current; }
- pointer operator->() const { return &(operator*()); }
-
-
-
- void advance_past_end() {
- while ( col_current == row_current->TWOD_END_() ) {
- ++row_current;
- if ( row_current != row_end )
- col_current = row_current->TWOD_BEGIN_();
- else
- break;
- }
- }
- iterator& operator++() {
- assert(row_current != row_end);
- ++col_current;
- advance_past_end();
- return *this;
- }
- iterator& operator--() {
- while ( row_current == row_end ||
- col_current == row_current->TWOD_BEGIN_() ) {
- assert(row_current != row_begin);
- --row_current;
- col_current = row_current->TWOD_END_();
- }
- --col_current;
- return *this;
- }
- iterator operator++(int) { iterator tmp(*this); ++*this; return tmp; }
- iterator operator--(int) { iterator tmp(*this); --*this; return tmp; }
-
- bool operator==(const iterator& it) const {
- return ( row_begin == it.row_begin &&
- row_end == it.row_end &&
- row_current == it.row_current &&
- (row_current == row_end || col_current == it.col_current) );
- }
- bool operator!=(const iterator& it) const { return !(*this == it); }
-
-
- typename containertype::iterator row_begin, row_end, row_current;
- typename containertype::value_type::TWOD_ITER_ col_current;
- };
- template <class containertype>
- class const_two_d_iterator {
- public:
- typedef const_two_d_iterator iterator;
- typedef std::bidirectional_iterator_tag iterator_category;
-
- typedef typename containertype::value_type _tmp_vt;
- typedef typename _tmp_vt::value_type value_type;
- typedef typename _tmp_vt::difference_type difference_type;
- typedef typename _tmp_vt::const_reference reference;
- typedef typename _tmp_vt::const_pointer pointer;
- const_two_d_iterator(typename containertype::const_iterator begin,
- typename containertype::const_iterator end,
- typename containertype::const_iterator curr)
- : row_begin(begin), row_end(end), row_current(curr), col_current() {
- if ( curr != end ) {
- col_current = curr->TWOD_BEGIN_();
- advance_past_end();
- }
- }
- const_two_d_iterator(typename containertype::const_iterator begin,
- typename containertype::const_iterator end,
- typename containertype::const_iterator curr,
- typename containertype::value_type::TWOD_CONST_ITER_ col)
- : row_begin(begin), row_end(end), row_current(curr), col_current(col) {
- advance_past_end();
- }
- const_two_d_iterator()
- : row_begin(), row_end(), row_current(), col_current() {
- }
-
- const_two_d_iterator(const two_d_iterator<containertype>& it) :
- row_begin(it.row_begin), row_end(it.row_end), row_current(it.row_current),
- col_current(it.col_current) { }
- typename containertype::const_iterator row_begin, row_end, row_current;
- typename containertype::value_type::TWOD_CONST_ITER_ col_current;
-
- reference operator*() const { return *col_current; }
- pointer operator->() const { return &(operator*()); }
- void advance_past_end() {
- while ( col_current == row_current->TWOD_END_() ) {
- ++row_current;
- if ( row_current != row_end )
- col_current = row_current->TWOD_BEGIN_();
- else
- break;
- }
- }
- iterator& operator++() {
- assert(row_current != row_end);
- ++col_current;
- advance_past_end();
- return *this;
- }
- iterator& operator--() {
- while ( row_current == row_end ||
- col_current == row_current->TWOD_BEGIN_() ) {
- assert(row_current != row_begin);
- --row_current;
- col_current = row_current->TWOD_END_();
- }
- --col_current;
- return *this;
- }
- iterator operator++(int) { iterator tmp(*this); ++*this; return tmp; }
- iterator operator--(int) { iterator tmp(*this); --*this; return tmp; }
- bool operator==(const iterator& it) const {
- return ( row_begin == it.row_begin &&
- row_end == it.row_end &&
- row_current == it.row_current &&
- (row_current == row_end || col_current == it.col_current) );
- }
- bool operator!=(const iterator& it) const { return !(*this == it); }
- };
- template <class containertype>
- class destructive_two_d_iterator {
- public:
- typedef destructive_two_d_iterator iterator;
- typedef std::input_iterator_tag iterator_category;
-
- typedef typename containertype::value_type _tmp_vt;
- typedef typename _tmp_vt::value_type value_type;
- typedef typename _tmp_vt::difference_type difference_type;
- typedef typename _tmp_vt::reference reference;
- typedef typename _tmp_vt::pointer pointer;
- destructive_two_d_iterator(typename containertype::iterator begin,
- typename containertype::iterator end,
- typename containertype::iterator curr)
- : row_begin(begin), row_end(end), row_current(curr), col_current() {
- if ( curr != end ) {
- col_current = curr->TWOD_BEGIN_();
- advance_past_end();
- }
- }
- destructive_two_d_iterator(typename containertype::iterator begin,
- typename containertype::iterator end,
- typename containertype::iterator curr,
- typename containertype::value_type::TWOD_ITER_ col)
- : row_begin(begin), row_end(end), row_current(curr), col_current(col) {
- advance_past_end();
- }
- destructive_two_d_iterator()
- : row_begin(), row_end(), row_current(), col_current() {
- }
- typename containertype::iterator row_begin, row_end, row_current;
- typename containertype::value_type::TWOD_ITER_ col_current;
-
- void advance_past_end() {
- while ( col_current == row_current->TWOD_END_() ) {
- row_current->clear();
-
- ++row_current;
- if ( row_current != row_end )
- col_current = row_current->TWOD_BEGIN_();
- else
- break;
- }
- }
-
- reference operator*() const { return *col_current; }
- pointer operator->() const { return &(operator*()); }
- iterator& operator++() {
- assert(row_current != row_end);
- ++col_current;
- advance_past_end();
- return *this;
- }
- iterator operator++(int) { iterator tmp(*this); ++*this; return tmp; }
- bool operator==(const iterator& it) const {
- return ( row_begin == it.row_begin &&
- row_end == it.row_end &&
- row_current == it.row_current &&
- (row_current == row_end || col_current == it.col_current) );
- }
- bool operator!=(const iterator& it) const { return !(*this == it); }
- };
- #undef TWOD_BEGIN_
- #undef TWOD_END_
- #undef TWOD_ITER_
- #undef TWOD_CONST_ITER_
- template <class T, u_int16_t GROUP_SIZE, class Alloc>
- class sparsegroup {
- private:
- typedef typename Alloc::template rebind<T>::other value_alloc_type;
- public:
-
- typedef T value_type;
- typedef Alloc allocator_type;
- typedef typename value_alloc_type::reference reference;
- typedef typename value_alloc_type::const_reference const_reference;
- typedef typename value_alloc_type::pointer pointer;
- typedef typename value_alloc_type::const_pointer const_pointer;
- typedef table_iterator<sparsegroup<T, GROUP_SIZE, Alloc> > iterator;
- typedef const_table_iterator<sparsegroup<T, GROUP_SIZE, Alloc> >
- const_iterator;
- typedef table_element_adaptor<sparsegroup<T, GROUP_SIZE, Alloc> >
- element_adaptor;
- typedef u_int16_t size_type;
- typedef int16_t difference_type;
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- typedef std::reverse_iterator<iterator> reverse_iterator;
-
-
- typedef pointer nonempty_iterator;
- typedef const_pointer const_nonempty_iterator;
- typedef std::reverse_iterator<nonempty_iterator> reverse_nonempty_iterator;
- typedef std::reverse_iterator<const_nonempty_iterator> const_reverse_nonempty_iterator;
-
- iterator begin() { return iterator(this, 0); }
- const_iterator begin() const { return const_iterator(this, 0); }
- iterator end() { return iterator(this, size()); }
- const_iterator end() const { return const_iterator(this, size()); }
- reverse_iterator rbegin() { return reverse_iterator(end()); }
- const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
- reverse_iterator rend() { return reverse_iterator(begin()); }
- const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
-
- nonempty_iterator nonempty_begin() { return group; }
- const_nonempty_iterator nonempty_begin() const { return group; }
- nonempty_iterator nonempty_end() {
- return group + settings.num_buckets;
- }
- const_nonempty_iterator nonempty_end() const {
- return group + settings.num_buckets;
- }
- reverse_nonempty_iterator nonempty_rbegin() {
- return reverse_nonempty_iterator(nonempty_end());
- }
- const_reverse_nonempty_iterator nonempty_rbegin() const {
- return const_reverse_nonempty_iterator(nonempty_end());
- }
- reverse_nonempty_iterator nonempty_rend() {
- return reverse_nonempty_iterator(nonempty_begin());
- }
- const_reverse_nonempty_iterator nonempty_rend() const {
- return const_reverse_nonempty_iterator(nonempty_begin());
- }
-
-
- const_reference default_value() const {
- static value_type defaultval = value_type();
- return defaultval;
- }
- private:
-
- static size_type charbit(size_type i) { return i >> 3; }
- static size_type modbit(size_type i) { return 1 << (i&7); }
- int bmtest(size_type i) const { return bitmap[charbit(i)] & modbit(i); }
- void bmset(size_type i) { bitmap[charbit(i)] |= modbit(i); }
- void bmclear(size_type i) { bitmap[charbit(i)] &= ~modbit(i); }
- pointer allocate_group(size_type n) {
- pointer retval = settings.allocate(n);
- if (retval == NULL) {
-
-
-
- fprintf(stderr, "sparsehash FATAL ERROR: failed to allocate %lu groups\n",
- static_cast<unsigned long>(n));
- exit(1);
- }
- return retval;
- }
- void free_group() {
- if (!group) return;
- pointer end_it = group + settings.num_buckets;
- for (pointer p = group; p != end_it; ++p)
- p->~value_type();
- settings.deallocate(group, settings.num_buckets);
- group = NULL;
- }
- static size_type bits_in_char(unsigned char c) {
-
-
- static const char bits_in[256] = {
- 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
- 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
- 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
- 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
- 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
- 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
- };
- return bits_in[c];
- }
- public:
-
-
-
-
-
-
-
-
- static size_type pos_to_offset(const unsigned char *bm, size_type pos) {
- size_type retval = 0;
-
-
- for ( ; pos > 8; pos -= 8 )
- retval += bits_in_char(*bm++);
- return retval + bits_in_char(*bm & ((1 << pos)-1));
- }
- size_type pos_to_offset(size_type pos) const {
- return pos_to_offset(bitmap, pos);
- }
-
-
-
-
-
- static size_type offset_to_pos(const unsigned char *bm, size_type offset) {
- size_type retval = 0;
-
- const size_type group_size = (GROUP_SIZE-1) / 8 + 1;
- for (size_type i = 0; i < group_size; i++) {
- const size_type pop_count = bits_in_char(*bm);
- if (pop_count > offset) {
- unsigned char last_bm = *bm;
- for (; offset > 0; offset--) {
- last_bm &= (last_bm-1);
- }
-
-
-
- last_bm = (last_bm & -last_bm) - 1;
- retval += bits_in_char(last_bm);
- return retval;
- }
- offset -= pop_count;
- retval += 8;
- bm++;
- }
- return retval;
- }
- size_type offset_to_pos(size_type offset) const {
- return offset_to_pos(bitmap, offset);
- }
- public:
-
- explicit sparsegroup(allocator_type& a) :
- group(0), settings(alloc_impl<value_alloc_type>(a)) {
- memset(bitmap, 0, sizeof(bitmap));
- }
- sparsegroup(const sparsegroup& x) : group(0), settings(x.settings) {
- if ( settings.num_buckets ) {
- group = allocate_group(x.settings.num_buckets);
- std::uninitialized_copy(x.group, x.group + x.settings.num_buckets, group);
- }
- memcpy(bitmap, x.bitmap, sizeof(bitmap));
- }
- ~sparsegroup() { free_group(); }
-
-
-
- sparsegroup &operator=(const sparsegroup& x) {
- if ( &x == this ) return *this;
- if ( x.settings.num_buckets == 0 ) {
- free_group();
- } else {
- pointer p = allocate_group(x.settings.num_buckets);
- std::uninitialized_copy(x.group, x.group + x.settings.num_buckets, p);
- free_group();
- group = p;
- }
- memcpy(bitmap, x.bitmap, sizeof(bitmap));
- settings.num_buckets = x.settings.num_buckets;
- return *this;
- }
-
- void swap(sparsegroup& x) {
- std::swap(group, x.group);
- for ( int i = 0; i < sizeof(bitmap) / sizeof(*bitmap); ++i )
- std::swap(bitmap[i], x.bitmap[i]);
- std::swap(settings.num_buckets, x.settings.num_buckets);
-
- }
-
- void clear() {
- free_group();
- memset(bitmap, 0, sizeof(bitmap));
- settings.num_buckets = 0;
- }
-
-
- size_type size() const { return GROUP_SIZE; }
- size_type max_size() const { return GROUP_SIZE; }
- bool empty() const { return false; }
-
- size_type num_nonempty() const { return settings.num_buckets; }
-
-
- const_reference get(size_type i) const {
- if ( bmtest(i) )
- return group[pos_to_offset(bitmap, i)];
- else
- return default_value();
- }
-
-
-
- const_reference unsafe_get(size_type i) const {
- assert(bmtest(i));
- return group[pos_to_offset(bitmap, i)];
- }
-
- reference mutating_get(size_type i) {
- if ( !bmtest(i) )
- set(i, default_value());
- return group[pos_to_offset(bitmap, i)];
- }
-
-
- const_reference operator[](size_type i) const {
- return get(i);
- }
- element_adaptor operator[](size_type i) {
- return element_adaptor(this, i);
- }
- private:
-
-
-
-
-
-
-
- void set_aux(size_type offset, base::true_type) {
- group = settings.realloc_or_die(group, settings.num_buckets+1);
-
-
- for (size_type i = settings.num_buckets; i > offset; --i)
-
-
- memcpy(static_cast<void*>(group + i), group + i-1, sizeof(*group));
- }
-
-
- void set_aux(size_type offset, base::false_type) {
-
- pointer p = allocate_group(settings.num_buckets + 1);
- std::uninitialized_copy(group, group + offset, p);
- std::uninitialized_copy(group + offset, group + settings.num_buckets,
- p + offset + 1);
- free_group();
- group = p;
- }
- public:
-
-
-
- reference set(size_type i, const_reference val) {
- size_type offset = pos_to_offset(bitmap, i);
- if ( bmtest(i) ) {
-
- group[offset].~value_type();
- } else {
- typedef base::integral_constant<bool,
- (base::has_trivial_copy<value_type>::value &&
- base::has_trivial_destructor<value_type>::value &&
- base::is_same<
- allocator_type,
- libc_allocator_with_realloc<value_type> >::value)>
- realloc_and_memmove_ok;
- set_aux(offset, realloc_and_memmove_ok());
- ++settings.num_buckets;
- bmset(i);
- }
-
-
- new(&group[offset]) value_type(val);
- return group[offset];
- }
-
- bool test(size_type i) const {
- return bmtest(i) != 0;
- }
- bool test(iterator pos) const {
- return bmtest(pos.pos) != 0;
- }
- private:
-
-
-
-
-
-
-
- void erase_aux(size_type offset, base::true_type) {
-
-
- group[offset].~value_type();
-
-
- assert(settings.num_buckets > 0);
- for (size_type i = offset; i < settings.num_buckets-1; ++i)
-
-
-
- memcpy(static_cast<void*>(group + i), group + i+1, sizeof(*group));
- group = settings.realloc_or_die(group, settings.num_buckets-1);
- }
-
-
- void erase_aux(size_type offset, base::false_type) {
-
- pointer p = allocate_group(settings.num_buckets - 1);
- std::uninitialized_copy(group, group + offset, p);
- std::uninitialized_copy(group + offset + 1, group + settings.num_buckets,
- p + offset);
- free_group();
- group = p;
- }
- public:
-
-
-
-
- void erase(size_type i) {
- if ( bmtest(i) ) {
- size_type offset = pos_to_offset(bitmap,i);
- if ( settings.num_buckets == 1 ) {
- free_group();
- group = NULL;
- } else {
- typedef base::integral_constant<bool,
- (base::has_trivial_copy<value_type>::value &&
- base::has_trivial_destructor<value_type>::value &&
- base::is_same<
- allocator_type,
- libc_allocator_with_realloc<value_type> >::value)>
- realloc_and_memmove_ok;
- erase_aux(offset, realloc_and_memmove_ok());
- }
- --settings.num_buckets;
- bmclear(i);
- }
- }
- void erase(iterator pos) {
- erase(pos.pos);
- }
- void erase(iterator start_it, iterator end_it) {
-
-
- for ( ; start_it != end_it; ++start_it )
- erase(start_it);
- }
-
-
-
-
- template <typename OUTPUT> bool write_metadata(OUTPUT *fp) const {
-
- assert(sizeof(settings.num_buckets) == 2);
- if ( !sparsehash_internal::write_bigendian_number(fp, settings.num_buckets,
- 2) )
- return false;
- if ( !sparsehash_internal::write_data(fp, bitmap, sizeof(bitmap)) )
- return false;
- return true;
- }
-
- template <typename INPUT> bool read_metadata(INPUT *fp) {
- clear();
- if ( !sparsehash_internal::read_bigendian_number(fp, &settings.num_buckets,
- 2) )
- return false;
- if ( !sparsehash_internal::read_data(fp, bitmap, sizeof(bitmap)) )
- return false;
-
-
- group = allocate_group(settings.num_buckets);
- return true;
- }
-
- template <typename INPUT> bool read_nopointer_data(INPUT *fp) {
- for ( nonempty_iterator it = nonempty_begin();
- it != nonempty_end(); ++it ) {
- if ( !sparsehash_internal::read_data(fp, &(*it), sizeof(*it)) )
- return false;
- }
- return true;
- }
-
-
-
- template <typename OUTPUT> bool write_nopointer_data(OUTPUT *fp) const {
- for ( const_nonempty_iterator it = nonempty_begin();
- it != nonempty_end(); ++it ) {
- if ( !sparsehash_internal::write_data(fp, &(*it), sizeof(*it)) )
- return false;
- }
- return true;
- }
-
-
-
-
-
- bool operator==(const sparsegroup& x) const {
- return ( settings.num_buckets == x.settings.num_buckets &&
- memcmp(bitmap, x.bitmap, sizeof(bitmap)) == 0 &&
- std::equal(begin(), end(), x.begin()) );
- }
- bool operator<(const sparsegroup& x) const {
- return std::lexicographical_compare(begin(), end(), x.begin(), x.end());
- }
- bool operator!=(const sparsegroup& x) const { return !(*this == x); }
- bool operator<=(const sparsegroup& x) const { return !(x < *this); }
- bool operator>(const sparsegroup& x) const { return x < *this; }
- bool operator>=(const sparsegroup& x) const { return !(*this < x); }
- private:
- template <class A>
- class alloc_impl : public A {
- public:
- typedef typename A::pointer pointer;
- typedef typename A::size_type size_type;
-
- alloc_impl(const A& a) : A(a) { }
-
-
- pointer realloc_or_die(pointer , size_type ) {
- fprintf(stderr, "realloc_or_die is only supported for "
- "libc_allocator_with_realloc\n");
- exit(1);
- return NULL;
- }
- };
-
-
- template <class A>
- class alloc_impl<libc_allocator_with_realloc<A> >
- : public libc_allocator_with_realloc<A> {
- public:
- typedef typename libc_allocator_with_realloc<A>::pointer pointer;
- typedef typename libc_allocator_with_realloc<A>::size_type size_type;
- alloc_impl(const libc_allocator_with_realloc<A>& a)
- : libc_allocator_with_realloc<A>(a) { }
- pointer realloc_or_die(pointer ptr, size_type n) {
- pointer retval = this->reallocate(ptr, n);
- if (retval == NULL) {
- fprintf(stderr, "sparsehash: FATAL ERROR: failed to reallocate "
- "%lu elements for ptr %p", static_cast<unsigned long>(n), ptr);
- exit(1);
- }
- return retval;
- }
- };
-
-
-
-
- class Settings : public alloc_impl<value_alloc_type> {
- public:
- Settings(const alloc_impl<value_alloc_type>& a, u_int16_t n = 0)
- : alloc_impl<value_alloc_type>(a), num_buckets(n) { }
- Settings(const Settings& s)
- : alloc_impl<value_alloc_type>(s), num_buckets(s.num_buckets) { }
- u_int16_t num_buckets;
- };
-
- pointer group;
- Settings settings;
- unsigned char bitmap[(GROUP_SIZE-1)/8 + 1];
- };
- template <class T, u_int16_t GROUP_SIZE, class Alloc>
- inline void swap(sparsegroup<T,GROUP_SIZE,Alloc> &x,
- sparsegroup<T,GROUP_SIZE,Alloc> &y) {
- x.swap(y);
- }
- template <class T, u_int16_t GROUP_SIZE = DEFAULT_SPARSEGROUP_SIZE,
- class Alloc = libc_allocator_with_realloc<T> >
- class sparsetable {
- private:
- typedef typename Alloc::template rebind<T>::other value_alloc_type;
- typedef typename Alloc::template rebind<
- sparsegroup<T, GROUP_SIZE, value_alloc_type> >::other vector_alloc;
- public:
-
- typedef T value_type;
- typedef Alloc allocator_type;
- typedef typename value_alloc_type::size_type size_type;
- typedef typename value_alloc_type::difference_type difference_type;
- typedef typename value_alloc_type::reference reference;
- typedef typename value_alloc_type::const_reference const_reference;
- typedef typename value_alloc_type::pointer pointer;
- typedef typename value_alloc_type::const_pointer const_pointer;
- typedef table_iterator<sparsetable<T, GROUP_SIZE, Alloc> > iterator;
- typedef const_table_iterator<sparsetable<T, GROUP_SIZE, Alloc> >
- const_iterator;
- typedef table_element_adaptor<sparsetable<T, GROUP_SIZE, Alloc> >
- element_adaptor;
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- typedef std::reverse_iterator<iterator> reverse_iterator;
-
-
- typedef two_d_iterator< std::vector< sparsegroup<value_type, GROUP_SIZE,
- value_alloc_type>,
- vector_alloc> >
- nonempty_iterator;
- typedef const_two_d_iterator< std::vector< sparsegroup<value_type,
- GROUP_SIZE,
- value_alloc_type>,
- vector_alloc> >
- const_nonempty_iterator;
- typedef std::reverse_iterator<nonempty_iterator> reverse_nonempty_iterator;
- typedef std::reverse_iterator<const_nonempty_iterator> const_reverse_nonempty_iterator;
-
- typedef destructive_two_d_iterator< std::vector< sparsegroup<value_type,
- GROUP_SIZE,
- value_alloc_type>,
- vector_alloc> >
- destructive_iterator;
-
- iterator begin() { return iterator(this, 0); }
- const_iterator begin() const { return const_iterator(this, 0); }
- iterator end() { return iterator(this, size()); }
- const_iterator end() const { return const_iterator(this, size()); }
- reverse_iterator rbegin() { return reverse_iterator(end()); }
- const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
- reverse_iterator rend() { return reverse_iterator(begin()); }
- const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
-
- nonempty_iterator nonempty_begin() {
- return nonempty_iterator(groups.begin(), groups.end(), groups.begin());
- }
- const_nonempty_iterator nonempty_begin() const {
- return const_nonempty_iterator(groups.begin(),groups.end(), groups.begin());
- }
- nonempty_iterator nonempty_end() {
- return nonempty_iterator(groups.begin(), groups.end(), groups.end());
- }
- const_nonempty_iterator nonempty_end() const {
- return const_nonempty_iterator(groups.begin(), groups.end(), groups.end());
- }
- reverse_nonempty_iterator nonempty_rbegin() {
- return reverse_nonempty_iterator(nonempty_end());
- }
- const_reverse_nonempty_iterator nonempty_rbegin() const {
- return const_reverse_nonempty_iterator(nonempty_end());
- }
- reverse_nonempty_iterator nonempty_rend() {
- return reverse_nonempty_iterator(nonempty_begin());
- }
- const_reverse_nonempty_iterator nonempty_rend() const {
- return const_reverse_nonempty_iterator(nonempty_begin());
- }
- destructive_iterator destructive_begin() {
- return destructive_iterator(groups.begin(), groups.end(), groups.begin());
- }
- destructive_iterator destructive_end() {
- return destructive_iterator(groups.begin(), groups.end(), groups.end());
- }
- typedef sparsegroup<value_type, GROUP_SIZE, allocator_type> group_type;
- typedef std::vector<group_type, vector_alloc > group_vector_type;
- typedef typename group_vector_type::reference GroupsReference;
- typedef typename group_vector_type::const_reference GroupsConstReference;
- typedef typename group_vector_type::iterator GroupsIterator;
- typedef typename group_vector_type::const_iterator GroupsConstIterator;
-
- static size_type num_groups(size_type num) {
- return num == 0 ? 0 : ((num-1) / GROUP_SIZE) + 1;
- }
- u_int16_t pos_in_group(size_type i) const {
- return static_cast<u_int16_t>(i % GROUP_SIZE);
- }
- size_type group_num(size_type i) const {
- return i / GROUP_SIZE;
- }
- GroupsReference which_group(size_type i) {
- return groups[group_num(i)];
- }
- GroupsConstReference which_group(size_type i) const {
- return groups[group_num(i)];
- }
- public:
-
- explicit sparsetable(size_type sz = 0, Alloc alloc = Alloc())
- : groups(vector_alloc(alloc)), settings(alloc, sz) {
- groups.resize(num_groups(sz), group_type(settings));
- }
-
-
-
- void swap(sparsetable& x) {
- std::swap(groups, x.groups);
- std::swap(settings.table_size, x.settings.table_size);
- std::swap(settings.num_buckets, x.settings.num_buckets);
- }
-
- void clear() {
- GroupsIterator group;
- for ( group = groups.begin(); group != groups.end(); ++group ) {
- group->clear();
- }
- settings.num_buckets = 0;
- }
-
- allocator_type get_allocator() const {
- return allocator_type(settings);
- }
-
-
-
-
- size_type size() const { return settings.table_size; }
- size_type max_size() const { return settings.max_size(); }
- bool empty() const { return settings.table_size == 0; }
-
- size_type num_nonempty() const { return settings.num_buckets; }
-
- void resize(size_type new_size) {
- groups.resize(num_groups(new_size), group_type(settings));
- if ( new_size < settings.table_size) {
-
- if ( pos_in_group(new_size) > 0 )
- groups.back().erase(groups.back().begin() + pos_in_group(new_size),
- groups.back().end());
- settings.num_buckets = 0;
- GroupsConstIterator group;
- for ( group = groups.begin(); group != groups.end(); ++group )
- settings.num_buckets += group->num_nonempty();
- }
- settings.table_size = new_size;
- }
-
- bool test(size_type i) const {
- assert(i < settings.table_size);
- return which_group(i).test(pos_in_group(i));
- }
- bool test(iterator pos) const {
- return which_group(pos.pos).test(pos_in_group(pos.pos));
- }
- bool test(const_iterator pos) const {
- return which_group(pos.pos).test(pos_in_group(pos.pos));
- }
-
-
- const_reference get(size_type i) const {
- assert(i < settings.table_size);
- return which_group(i).get(pos_in_group(i));
- }
-
-
-
- const_reference unsafe_get(size_type i) const {
- assert(i < settings.table_size);
- assert(test(i));
- return which_group(i).unsafe_get(pos_in_group(i));
- }
-
- reference mutating_get(size_type i) {
- assert(i < settings.table_size);
- typename group_type::size_type old_numbuckets = which_group(i).num_nonempty();
- reference retval = which_group(i).mutating_get(pos_in_group(i));
- settings.num_buckets += which_group(i).num_nonempty() - old_numbuckets;
- return retval;
- }
-
- const_reference operator[](size_type i) const {
- return get(i);
- }
- element_adaptor operator[](size_type i) {
- return element_adaptor(this, i);
- }
-
- const_nonempty_iterator get_iter(size_type i) const {
- assert(test(i));
- return const_nonempty_iterator(
- groups.begin(), groups.end(),
- groups.begin() + group_num(i),
- (groups[group_num(i)].nonempty_begin() +
- groups[group_num(i)].pos_to_offset(pos_in_group(i))));
- }
-
- nonempty_iterator get_iter(size_type i) {
- assert(test(i));
- return nonempty_iterator(
- groups.begin(), groups.end(),
- groups.begin() + group_num(i),
- (groups[group_num(i)].nonempty_begin() +
- groups[group_num(i)].pos_to_offset(pos_in_group(i))));
- }
-
- size_type get_pos(const const_nonempty_iterator& it) const {
- difference_type current_row = it.row_current - it.row_begin;
- difference_type current_col = (it.col_current -
- groups[current_row].nonempty_begin());
- return ((current_row * GROUP_SIZE) +
- groups[current_row].offset_to_pos(current_col));
- }
-
-
- reference set(size_type i, const_reference val) {
- assert(i < settings.table_size);
- typename group_type::size_type old_numbuckets = which_group(i).num_nonempty();
- reference retval = which_group(i).set(pos_in_group(i), val);
- settings.num_buckets += which_group(i).num_nonempty() - old_numbuckets;
- return retval;
- }
-
-
- void erase(size_type i) {
- assert(i < settings.table_size);
- typename group_type::size_type old_numbuckets = which_group(i).num_nonempty();
- which_group(i).erase(pos_in_group(i));
- settings.num_buckets += which_group(i).num_nonempty() - old_numbuckets;
- }
- void erase(iterator pos) {
- erase(pos.pos);
- }
- void erase(iterator start_it, iterator end_it) {
-
-
- for ( ; start_it != end_it; ++start_it )
- erase(start_it);
- }
-
-
-
- private:
-
- typedef unsigned long MagicNumberType;
- static const MagicNumberType MAGIC_NUMBER = 0x24687531;
-
-
-
-
-
-
-
-
- template <typename OUTPUT, typename IntType>
- static bool write_32_or_64(OUTPUT* fp, IntType value) {
- if ( value < 0xFFFFFFFFULL ) {
- if ( !sparsehash_internal::write_bigendian_number(fp, value, 4) )
- return false;
- } else {
- if ( !sparsehash_internal::write_bigendian_number(fp, 0xFFFFFFFFUL, 4) )
- return false;
- if ( !sparsehash_internal::write_bigendian_number(fp, value, 8) )
- return false;
- }
- return true;
- }
- template <typename INPUT, typename IntType>
- static bool read_32_or_64(INPUT* fp, IntType *value) {
- MagicNumberType first4 = 0;
- if ( !sparsehash_internal::read_bigendian_number(fp, &first4, 4) )
- return false;
- if ( first4 < 0xFFFFFFFFULL ) {
- *value = first4;
- } else {
- if ( !sparsehash_internal::read_bigendian_number(fp, value, 8) )
- return false;
- }
- return true;
- }
- public:
-
-
- template <typename OUTPUT> bool write_metadata(OUTPUT *fp) const {
- if ( !write_32_or_64(fp, MAGIC_NUMBER) ) return false;
- if ( !write_32_or_64(fp, settings.table_size) ) return false;
- if ( !write_32_or_64(fp, settings.num_buckets) ) return false;
- GroupsConstIterator group;
- for ( group = groups.begin(); group != groups.end(); ++group )
- if ( group->write_metadata(fp) == false ) return false;
- return true;
- }
-
- template <typename INPUT> bool read_metadata(INPUT *fp) {
- size_type magic_read = 0;
- if ( !read_32_or_64(fp, &magic_read) ) return false;
- if ( magic_read != MAGIC_NUMBER ) {
- clear();
- return false;
- }
- if ( !read_32_or_64(fp, &settings.table_size) ) return false;
- if ( !read_32_or_64(fp, &settings.num_buckets) ) return false;
- resize(settings.table_size);
- GroupsIterator group;
- for ( group = groups.begin(); group != groups.end(); ++group )
- if ( group->read_metadata(fp) == false ) return false;
- return true;
- }
-
-
-
-
- bool write_nopointer_data(FILE *fp) const {
- for ( const_nonempty_iterator it = nonempty_begin();
- it != nonempty_end(); ++it ) {
- if ( !fwrite(&*it, sizeof(*it), 1, fp) ) return false;
- }
- return true;
- }
-
- bool read_nopointer_data(FILE *fp) {
- for ( nonempty_iterator it = nonempty_begin();
- it != nonempty_end(); ++it ) {
- if ( !fread(reinterpret_cast<void*>(&(*it)), sizeof(*it), 1, fp) )
- return false;
- }
- return true;
- }
-
-
-
-
-
- typedef sparsehash_internal::pod_serializer<value_type> NopointerSerializer;
-
- template <typename ValueSerializer, typename OUTPUT>
- bool serialize(ValueSerializer serializer, OUTPUT *fp) {
- if ( !write_metadata(fp) )
- return false;
- for ( const_nonempty_iterator it = nonempty_begin();
- it != nonempty_end(); ++it ) {
- if ( !serializer(fp, *it) ) return false;
- }
- return true;
- }
-
- template <typename ValueSerializer, typename INPUT>
- bool unserialize(ValueSerializer serializer, INPUT *fp) {
- clear();
- if ( !read_metadata(fp) )
- return false;
- for ( nonempty_iterator it = nonempty_begin();
- it != nonempty_end(); ++it ) {
- if ( !serializer(fp, &*it) ) return false;
- }
- return true;
- }
-
-
-
- bool operator==(const sparsetable& x) const {
- return ( settings.table_size == x.settings.table_size &&
- settings.num_buckets == x.settings.num_buckets &&
- groups == x.groups );
- }
- bool operator<(const sparsetable& x) const {
- return std::lexicographical_compare(begin(), end(), x.begin(), x.end());
- }
- bool operator!=(const sparsetable& x) const { return !(*this == x); }
- bool operator<=(const sparsetable& x) const { return !(x < *this); }
- bool operator>(const sparsetable& x) const { return x < *this; }
- bool operator>=(const sparsetable& x) const { return !(*this < x); }
- private:
-
-
-
-
- class Settings : public allocator_type {
- public:
- typedef typename allocator_type::size_type size_type;
- Settings(const allocator_type& a, size_type sz = 0, size_type n = 0)
- : allocator_type(a), table_size(sz), num_buckets(n) { }
- Settings(const Settings& s)
- : allocator_type(s),
- table_size(s.table_size), num_buckets(s.num_buckets) { }
- size_type table_size;
- size_type num_buckets;
- };
-
- group_vector_type groups;
- Settings settings;
- };
- template <class T, u_int16_t GROUP_SIZE, class Alloc>
- inline void swap(sparsetable<T,GROUP_SIZE,Alloc> &x,
- sparsetable<T,GROUP_SIZE,Alloc> &y) {
- x.swap(y);
- }
- _END_GOOGLE_NAMESPACE_
- #endif
|