b-tree sequence
sequence container optimized for inserting/deleting in random places
 All Classes Files Functions Typedefs
btree_seq.h
Go to the documentation of this file.
1 // Copyright (C) 2014 by Aleksandr Kupriianov
2 // email: alexkupri host: gmail dot com
3 
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See the file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
8 // Purpose: fast sequence declaration
9 // See documentation at http://alexkupri.github.io/array/
10 
11 
12 #ifndef __BTREE_SEQ_H
13 #define __BTREE_SEQ_H
14 
15 #include <assert.h>
16 #include <iterator>
17 
18 #if __cplusplus >= 201103L
19 
20 #include <initializer_list>
21 #include <utility>
22 
23 #endif
24 
29 // This is private namespace.
31 namespace ___alexkupri_helpers
32 {
33  struct my_false_type{};
34  struct my_true_type{};
35  template<typename _Tp> struct my_is_integer { typedef my_false_type __type; };
36  template<> struct my_is_integer<bool> { typedef my_true_type __type; };
37  template<> struct my_is_integer<char> { typedef my_true_type __type; };
38  template<> struct my_is_integer<signed char> { typedef my_true_type __type; };
39  template<> struct my_is_integer<unsigned char> { typedef my_true_type __type; };
40  template<> struct my_is_integer<short> { typedef my_true_type __type; };
41  template<> struct my_is_integer<unsigned short> { typedef my_true_type __type; };
42  template<> struct my_is_integer<int> { typedef my_true_type __type; };
43  template<> struct my_is_integer<unsigned int> { typedef my_true_type __type; };
44  template<> struct my_is_integer<long> { typedef my_true_type __type; };
45  template<> struct my_is_integer<unsigned long> { typedef my_true_type __type; };
46 }
48 
50 
60 template <typename T,int L=30,int M=60,typename A=std::allocator<T> >
61 class btree_seq
62 {
63 public:
65  typedef A allocator_type;
67  typedef typename A::value_type value_type;
69  typedef typename A::reference reference;
71  typedef typename A::const_reference const_reference;
73  typedef typename A::pointer pointer;
75  typedef typename A::const_pointer const_pointer;
77  typedef typename A::size_type size_type;
79  typedef typename A::difference_type difference_type;
81  typedef typename A::difference_type diff_type;
82 private:
83  //data types
84  //In the whole library Node* can be cast to either Branch* or Leaf*.
85  //This is determined entirely via depth variable.
86  struct Branch;
87  struct Node
88  {
89  Branch *parent;
90  };
91  struct Branch:public Node
92  {
93  Node* children[L];
94  size_type nums[L];
95  size_type fillament;
96  };
97  struct Leaf:public Node
98  {
99  value_type elements[M];
100  size_type fillament;
101  };
102  typedef typename allocator_type::template rebind<Branch>::other Branch_alloc_type;
103  typedef typename allocator_type::template rebind<Leaf>::other Leaf_alloc_type;
104  allocator_type T_alloc;
105  Branch_alloc_type branch_alloc;
106  Leaf_alloc_type leaf_alloc;
107  //Data
108  Node *root;
109  size_type depth,count;
110  //Element helper functions
111  void move_elements_inc(pointer dst,pointer src,size_type num);
112  void move_elements_dec(pointer dst,pointer limit,size_type num);
113  template <class InputIterator>
114  diff_type fill_elements(pointer dst,diff_type num,InputIterator &first,InputIterator last,
115  std::random_access_iterator_tag);
116  template <class InputIterator>
117  diff_type fill_elements(pointer dst,diff_type num,InputIterator &first,InputIterator last,
118  std::input_iterator_tag);
119  template <class InputIterator>
120  diff_type count_difference(InputIterator,InputIterator,diff_type limit,
121  std::input_iterator_tag){return limit+1;}
122  template <class InputIterator>
123  diff_type count_difference(InputIterator first,InputIterator last,diff_type,
124  std::random_access_iterator_tag){return last-first;}
125  void burn_elements(pointer ptr,size_type num);
126  //branch helpers
127  void insert_children(Branch *b,size_type idx,size_type num);
128  void delete_children(Branch *b,size_type idx,size_type num);
129  size_type move_children(Branch *dst,size_type idst,Branch *src,size_type isrc,size_type num);
130  size_type fill_leaves(Branch *b,size_type place,Leaf **l,size_type num);
131  //leaf balancing helpers
132  bool try_merge_leaves(Branch *b,size_type idx);
133  void balance_leaves_lr(Branch *b,size_type idx);
134  void balance_leaves_rl(Branch *b,size_type idx);
135  void delete_leaf(Leaf *l);
136  void underflow_leaf(Leaf *l);
137  //branch balancing helpers
138  bool try_merge_branches(Branch *b,size_type idx);
139  void balance_branch_lr(Branch *b,size_type idx);
140  void balance_branch_rl(Branch *b,size_type idx);
141  void underflow_branch(Branch *node);
142  //find and read functions
143  size_type find_leaf(Leaf *&l,size_type pos)const;
144  size_type find_leaf(Node *&l,size_type pos,difference_type increment,size_type depth_lim=0);
145  static size_type find_child(Branch *b,Node* c);
146  //some initialization functions
147  void init_tree();
148  void increase_depth(Branch *new_branch);
149  //splitting algorithms
150  Branch *reserve_enough_branches_splitting(Node* existing);
151  template <typename Alloc,typename Node_type>
152  void prepare_for_splitting(Branch *&branch_bundle,
153  Node_type *&result,Node_type *existing,Alloc &alloc);
154  void split(Node* existing,Node* right_to_existing,size_type right_count,Branch *branch_bundle);
155  void add_child(Branch* parent,Node* inserted,size_type elements,size_type pos,size_type rl,Branch *branch_bundle);
156  //underflow and sew functions
157  void deep_sew(size_type pos);
158  void my_deep_sew(size_type pos);
159  void advanced_sew_together(Leaf *last_leaf,size_type pos);
160  //helper functions and a class for inserting
161  size_type prepare_leaf_for_inserting
162  (size_type pos,diff_type num,Leaf *&res,Leaf **sibling);
163  void undo_preparing_to_insert
164  (size_type pos,diff_type num,Leaf *l,Leaf *sibling,size_type found);
165 
166  template <class InputIterator>
167  Leaf* start_inserting(size_type &pos,InputIterator &first,InputIterator last);
168  void insert_leaves(Leaf **l,size_type num_leaves,diff_type num_elems,size_type pos);
169  template <class InputIterator>
170  Leaf* insert_whole_leaves(size_type startpos,size_type &pos,InputIterator first,InputIterator last,Leaf *last_leaf);
171  class FillIterator
172  {
173  const_pointer ptr;
174  size_type j;
175  public:
176  //ok with default fns: op=, ~, copy cn
177  typedef std::random_access_iterator_tag iterator_category;
178  typedef
179  typename std::iterator<std::random_access_iterator_tag, T>::value_type
180  value_type;
181  typedef
182  typename std::iterator<std::random_access_iterator_tag, T>::difference_type
184  typedef
185  typename std::iterator<std::random_access_iterator_tag, T>::reference
186  reference;
187  typedef
188  typename std::iterator<std::random_access_iterator_tag, T>::pointer
189  pointer;
190 
191  //
192  FillIterator(const_pointer ptrptr,size_type jj):ptr(ptrptr),j(jj){};
193  const_reference operator*(){return *ptr;}
194  FillIterator &operator++(){j++;return *this;}
195  bool operator==(const FillIterator &that)const
196  { return j==that.j; }
197  bool operator!=(const FillIterator &that)const
198  { return j!=that.j; }
199  difference_type operator-(const FillIterator &that)const
200  {return static_cast<diff_type>(j)-static_cast<diff_type>(that.j);}
201  };
202  //helper function and classes for delete and iterative access
203  template<typename Action>
204  bool recursive_action(Action &act,size_type start,size_type diff,size_type dep,Node *node);
205  class erase_helper
206  {
207  Leaf *last_leaf;
208  size_type leaves;
209  btree_seq &aka;
210  public:
211  erase_helper(btree_seq &akaaka):last_leaf(0),leaves(0),aka(akaaka){}
212  void decrement_value(size_type &a,size_type b){a-=b;}
213  bool shift_array(){return true;}
214  bool process_leaf(Leaf *l,size_type start,size_type end);
215  Leaf *get_last_leaf(){return last_leaf;}
216  size_type num_leaves(){return leaves;}
217  };
218  template<typename V>
219  class visitor_helper
220  {
221  V &v;
222  size_type iters;
223  public:
224  visitor_helper(V &vv):v(vv),iters(0){};
225  void decrement_value(size_type &,size_type){}
226  bool shift_array(){return false;}
227  bool process_leaf(Leaf *l,size_type st,size_type fin);
228  size_type get_iters(){return iters;}
229  };
230  //attach and detach helpers
231  void detach_some(btree_seq<T,L,M,A> &that,Branch *b,size_type dep,bool last);
232  void insert_tree(btree_seq<T,L,M,A> &that,bool last);
233  //assign helpers
234  template <class Integer>
235  void impl_insert(size_type pos,Integer n,Integer val,___alexkupri_helpers::my_true_type)
236  {
237  fill(pos,static_cast<size_type>(n),val);
238  }
239  template <class InputIterator>
240  void impl_insert(size_type pos,InputIterator first,InputIterator last,___alexkupri_helpers::my_false_type)
241  {
242  insert(pos,first,last);
243  }
244  //others
245  void check_node(Node* c,size_type sum,bool nothead,size_type depth,Branch *parent);
246  template <class output_stream>
247  void output_node(output_stream &o,Node* c,size_type tabs,size_type depth);
248  static void my_assert(bool,const char*);
249  void assert_range(size_type n);
250 public:
252 
265  template<typename TT>
267  {
268  public:
270  typedef std::random_access_iterator_tag iterator_category;
272  typedef
273  typename std::iterator<std::random_access_iterator_tag, TT>::value_type
276  typedef
277  typename std::iterator<std::random_access_iterator_tag, TT>::difference_type
280  typedef
281  typename std::iterator<std::random_access_iterator_tag, TT>::reference
284  typedef
285  typename std::iterator<std::random_access_iterator_tag, TT>::pointer
287  private:
288  const btree_seq *tree;
289  size_type abs_idx;
290  mutable pointer elems;
291  mutable size_type avail_ptr;
292  mutable size_type rel_idx;
293  mutable Branch *br;
294  mutable size_type idx_in_br;
295  pointer rebase()const;
296  pointer access()const
297  {return (rel_idx<avail_ptr)?(elems+rel_idx):(rebase());}
298  public:
301  tree(0),abs_idx(),elems(),avail_ptr(0),rel_idx(),br(),idx_in_br(){};
304  tree(t),abs_idx(pos),elems(),avail_ptr(0),rel_idx(),br(0),idx_in_br(){};
307  tree(that.tree),
308  abs_idx(that.abs_idx),
309  elems(that.elems),
310  avail_ptr(that.avail_ptr),
311  rel_idx(that.rel_idx),
312  br(that.br),
313  idx_in_br(that.idx_in_br){};
315  template<typename T2>
317  tree(that.get_container()),
318  abs_idx(that.get_position()),
319  elems(that.__get_null_pointer()),
320  avail_ptr(0),
321  rel_idx(),
322  br(),
323  idx_in_br(){}
325  iterator_base& operator=(const iterator_base/*<T2>*/ &that)
326  {
327  elems=that.elems;
328  tree=that.tree;
329  abs_idx=that.abs_idx;
330  rel_idx=that.rel_idx;
331  avail_ptr=that.avail_ptr;
332  idx_in_br=that.idx_in_br;
333  br=that.br;
334  return *this;
335  }
337  template<typename T2>
339  {
340  tree=that.get_container();
341  abs_idx=that.get_position();
342  elems=that.__get_null_pointer();
343  avail_ptr=0;
344  return *this;
345  }
347  reference operator*()const{return *access();}
349  pointer operator->()const{return access();}
352  {iterator_base tmp(this);tmp+=n;return *tmp;};
353  //comparison operators, < > = != <= >=
355  template<typename T2>
356  bool operator==(const iterator_base<T2>& that)const
357  {return get_position()==that.get_position();}
359  template<typename T2>
360  bool operator!=(const iterator_base<T2>& that)const
361  {return get_position()!=that.get_position();}
363  template<typename T2>
364  bool operator>(const iterator_base<T2>& that)const
365  {return get_position()>that.get_position();}
367  template<typename T2>
368  bool operator<(const iterator_base<T2>& that)const
369  {return get_position()<that.get_position();}
371  template<typename T2>
372  bool operator>=(const iterator_base<T2>& that)const
373  {return get_position()>=that.get_position();}
375  template<typename T2>
376  bool operator<=(const iterator_base<T2>& that)const
377  {return get_position()<=that.get_position();}
379  template<typename T2>
381  {return static_cast<diff_type>(get_position())-
382  static_cast<diff_type>(that.get_position());}
384  iterator_base& operator++(){++abs_idx;++rel_idx;return *this;}
386  iterator_base& operator--(){--abs_idx;--rel_idx;return *this;}
388  iterator_base operator++(int){iterator_base tmp(*this);++(*this);return tmp;}
390  iterator_base operator--(int){iterator_base tmp(*this);--(*this);return tmp;}
392  iterator_base& operator+=(difference_type n){abs_idx=abs_idx+n;rel_idx=rel_idx+n;return *this;}
394  iterator_base& operator-=(difference_type n){abs_idx-=n;rel_idx-=n;return *this;}
397  {iterator_base tmp(*this);tmp+=n;return tmp;}
400  {iterator_base tmp(*this);tmp-=n;return tmp;}
402  size_type get_position()const{return abs_idx;}
404  const btree_seq* get_container()const{return tree;}
406  pointer __get_null_pointer()const{return 0;}
407  };
413  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
415  typedef std::reverse_iterator<iterator> reverse_iterator;
417 
420  explicit btree_seq(const allocator_type &alloc=allocator_type())
421  :T_alloc(alloc),branch_alloc(alloc),leaf_alloc(alloc),root(),count(0)
422  {
423  };
425 
429  :T_alloc(that.T_alloc),branch_alloc(that.T_alloc),leaf_alloc(that.T_alloc),
430  root(),count(0)
431  {
432  const_iterator first=that.begin(),last=that.end();
433  insert(0,first,last);
434  }
436 
441  explicit btree_seq(size_type n,const value_type &val,
442  const allocator_type &alloc=allocator_type())
443  :T_alloc(alloc),branch_alloc(alloc),leaf_alloc(alloc),root(),count(0)
444  {
445  fill(0,n,val);
446  }
448 
453  template <typename Iterator>
454  btree_seq(Iterator first,Iterator last,
455  const allocator_type &alloc=allocator_type())
456  :T_alloc(alloc),branch_alloc(alloc),leaf_alloc(alloc),root(),count(0)
457  {
458  typename ___alexkupri_helpers::my_is_integer<Iterator>::__type is_int_type;
459  impl_insert(0,first,last,is_int_type);
460  }
461  #if __cplusplus >= 201103L
462 
464 
467  btree_seq(btree_seq<T,L,M,A> &&that, const allocator_type &alloc=allocator_type()):T_alloc(alloc)
468  {
469  root=that.root;
470  count=that.count;
471  depth=that.depth;
472  that.count=0;
473  that.depth=0;
474  }
475 
477 
480  btree_seq(std::initializer_list<value_type> il,
481  const allocator_type &alloc=allocator_type())
482  :btree_seq(il.begin(),il.end(),alloc){}
483 
484  #endif
485 
487 
489  ~btree_seq(){erase(0,count);}
492 
495 
496  const_iterator begin()const{return const_iterator(this,0);}
498 
499  const_iterator end()const{return const_iterator(this,count);}
501 
502  const_iterator cbegin()const{return const_iterator(this,0);}
504 
505  const_iterator cend()const{return const_iterator(this,count);}
507 
508  iterator begin(){return iterator(this,0);}
510 
511  iterator end(){return iterator(this,count);}
513 
516 
519 
522 
525 
528 
531 
532  iterator iterator_at(size_type pos){return iterator(this,pos);}
534 
537 
540 
543 
548  {
549  Leaf *l=(Leaf*)root;
550  size_type found=depth?find_leaf(l,pos):pos;
551  T *ptr=l->elements;
552  return *(ptr+found);
553  }
555 
560  {
561  Leaf *l=(Leaf*)root;
562  size_type found=depth?find_leaf(l,pos):pos;
563  const T *ptr=l->elements;
564  return *(ptr+found);
565  }
567  size_type size()const{return count;}
569 
573  assert_range(pos);
574  return (*this)[pos];
575  }
577 
581  assert_range(pos);
582  return (*this)[pos];
583  }
585 
586  reference front(){return (*this)[0];}
588 
589  const_reference front()const{return (*this)[0];}
591 
592  reference back(){return (*this)[size()-1];}
594 
595  const_reference back()const{return (*this)[size()-1];}
597  bool empty()const{return count==0;}
599 
610  template<typename V>
611  size_type visit(size_type first,size_type last,V& v);
613 
615 
618 
623  void insert(size_type pos,const value_type& val)
624  {
625  Leaf *l;
626  size_type found=prepare_leaf_for_inserting(pos,1,l,0);
627  try{
628  T_alloc.construct(l->elements+found,val);
629  }catch(...){
630  undo_preparing_to_insert(pos,1,l,0,found);
631  throw;
632  }
633  }
635 
640  template <class InputIterator>
641  void insert(size_type pos,InputIterator first,InputIterator last);
643 
650  {
651  size_type position=pos.get_position();
652  insert(position,val);
653  return iterator_at(position);
654  }
656 
664  {
665  size_type position=pos.get_position();
666  fill(position,n,val);
667  return iterator_at(position);
668  }
670 
677  template<class InputIterator>
678  iterator insert(const_iterator pos,InputIterator first,InputIterator last)
679  {
680  typename ___alexkupri_helpers::my_is_integer<InputIterator>::__type is_int_type;
681  size_type position=pos.get_position();
682  impl_insert(position,first,last,is_int_type);
683  return iterator_at(position);
684  }
685  #if __cplusplus >= 201103L
686 
690  void insert(size_type pos,value_type&& val)
691  {
692  emplace(pos,std::move(val));
693  }
694 
696 
701  {
702  size_type position=pos.get_position();
703  emplace(position,std::move(val));
704  return iterator_at(position);
705  }
706 
708 
710  void insert(size_type pos,std::initializer_list<value_type> il)
711  {
712  insert(pos,il.begin(),il.end());
713  }
714 
716 
719  iterator insert(const_iterator pos,std::initializer_list<value_type> il)
720  {
721  size_type position=pos.get_position();
722  insert(position,il.begin(),il.end());
723  return iterator_at(position);
724  }
725  #endif
726 
732  void fill(size_type pos,size_type repetition,const value_type& val)
733  {
734  FillIterator first(&val,0),last(&val,repetition);
735  insert(pos,first,last);
736  }
738 
740  void resize(size_type n,const value_type& val = value_type());
742 
746  void erase(size_type first,size_type last);
748 
754  {
755  size_type position=pos.get_position();
756  erase(position,position+1);
757  return iterator_at(position);
758  }
760 
767  {
768  size_type first_position=first.get_position(),last_position=last.get_position();
769  erase(first_position,last_position);
770  return iterator_at(first_position);
771  }
773 
774  void push_back(const value_type &val)
775  { insert(count,val); }
777 
778  void push_front(const value_type &val)
779  { insert(0,val); }
781 
782  void pop_back()
783  { erase(count-1,count); }
785 
786  void pop_front()
787  { erase(0,1); }
788  #if __cplusplus >= 201103L
789  void push_back(value_type &&val)
791  {
792  emplace(count,std::move(val));
793  }
794 
796  void push_front(value_type &&val)
797  {
798  emplace(0,std::move(val));
799  }
800 
802 
805  template <class ...Args>
806  void emplace(size_type pos,Args&&... args)
807  {
808  Leaf *l;
809  size_type found=prepare_leaf_for_inserting(pos,1,l,0);
810  try{
811  T_alloc.construct(l->elements+found,std::forward<Args>(args)...);
812  }catch(...){
813  undo_preparing_to_insert(pos,1,l,0,found);
814  throw;
815  }
816  }
817 
819 
822  template <class ...Args>
823  iterator emplace(const_iterator pos,Args&&... args)
824  {
825  size_type position=pos.get_position();
826  emplace(position,std::forward<Args>(args)...);
827  return iterator_at(position);
828  }
829 
831  template <class ...Args>
832  void emplace_front(Args&&... args)
833  {
834  emplace(0,std::forward<Args>(args)...);
835  }
836 
838  template <class... Args>
839  void emplace_back(Args&&... args)
840  {
841  emplace(count,std::forward<Args>(args)...);
842  }
843 
844  #endif
845 
848 
851 
855  {
856  const_iterator first=that.begin(),last=that.end();
857  clear();
858  insert(0,first,last);
859  return *this;
860  }
862 
864  void swap(btree_seq<T,L,M,A> &that);
866 
867  void clear(){erase(0,count);}
869 
873  void assign(size_type n,const value_type &val);
875 
879  template <class InputIterator>
880  void assign(InputIterator first,InputIterator last)
881  {
882  typename ___alexkupri_helpers::my_is_integer<InputIterator>::__type is_int_type;
883  clear();
884  impl_insert(0,first,last,is_int_type);
885  }
887 
897 
907 
915  void split_right(btree_seq<T,L,M,A> &that,size_type pos);
917 
925  void split_left(btree_seq<T,L,M,A> &that,size_type pos);
926 
927  #if __cplusplus >= 201103L
928 
932  {
933  clear();
934  swap(that);
935  return *this;
936  }
937 
939 
941  btree_seq &operator=(std::initializer_list<value_type> il)
942  {
943  assign(il);
944  return *this;
945  }
946 
948 
950  void assign(std::initializer_list<value_type> il)
951  {
952  clear();
953  insert(0,il.begin(),il.end());
954  }
955 
956  #endif
957 
959 
962 
965 
967  void __check_consistency();
969  template <class output_stream>
970  void __output(output_stream &o,const char *comm="");
976  size_type __branch_size(){return sizeof(Branch);}
978  size_type __leaf_size(){return sizeof(Leaf);}
980  void reserve(size_type n){/*NOTHING*/}
982  void shrink_to_fit(){/*NOTHING*/}
984  allocator_type get_allocator()const{return T_alloc;}
986 };
987 
989 template <typename T,int L,int M,typename A>
991 {
992  first.swap(second);
993 }
994 
996 template <typename T,int L,int M,typename A>
997 bool operator<(const btree_seq<T,L,M,A> &x,const btree_seq<T,L,M,A> &y)
998  { return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
999 
1001 template <typename T,int L,int M,typename A>
1003  { return (y<x); }
1004 
1006 template <typename T,int L,int M,typename A>
1007 bool operator<=(const btree_seq<T,L,M,A> &x,const btree_seq<T,L,M,A> &y)
1008  { return !(y<x); }
1009 
1011 template <typename T,int L,int M,typename A>
1013  { return !(x<y); }
1014 
1016 template <typename T,int L,int M,typename A>
1018  { return (x.size() == y.size()
1019  && std::equal(x.begin(), x.end(), y.begin())); }
1020 
1022 template <typename T,int L,int M,typename A>
1024  { return !(x==y); }
1025 
1026 
1027 #include "btree_seq2.h"
1028 
1029 #endif /*__BTREE_SEQ_H*/
void pop_front()
Removes the first element.
Definition: btree_seq.h:786
iterator insert(const_iterator pos, const value_type &val)
Compatible function for inserting the single element.
Definition: btree_seq.h:649
iterator_base operator--(int)
Postdecrement.
Definition: btree_seq.h:390
btree_seq & operator=(btree_seq< T, L, M, A > &&that)
Move operator= (C++11)
Definition: btree_seq.h:931
void insert(size_type pos, value_type &&val)
Native inserting of rvalue (C++11)
Definition: btree_seq.h:690
Iterator template for const_iterator and iterator.
Definition: btree_seq.h:266
A allocator_type
The last template parameter, allocator.
Definition: btree_seq.h:65
reverse_iterator rend()
Return reverse iterator to reverse end.
Definition: btree_seq.h:529
void __check_consistency()
Checks consistency of the container (debug).
bool operator>(const btree_seq< T, L, M, A > &x, const btree_seq< T, L, M, A > &y)
Lexicographical comparison.
Definition: btree_seq.h:1002
btree_seq & operator=(std::initializer_list< value_type > il)
Initializer list operator= (C++11)
Definition: btree_seq.h:941
A::const_reference const_reference
Constant reference type, const T&.
Definition: btree_seq.h:71
void push_front(const value_type &val)
Adds element to the beginning of the sequence.
Definition: btree_seq.h:778
A::difference_type difference_type
Signed integer type, ptr_diff_t (int).
Definition: btree_seq.h:79
void emplace(size_type pos, Args &&...args)
Native emplace function (C++11)
Definition: btree_seq.h:806
A::reference reference
Reference type, T&.
Definition: btree_seq.h:69
iterator_base()
Default constructor.
Definition: btree_seq.h:300
void split_left(btree_seq< T, L, M, A > &that, size_type pos)
Fast split, leaving left piece in that container.
size_type visit(size_type first, size_type last, V &v)
Sequential search/modify operation on the range.
size_type __children_in_branch()
Returns L (second parameter of the template) (profile, RTTI).
Definition: btree_seq.h:972
btree_seq(const allocator_type &alloc=allocator_type())
Empty container constructor.
Definition: btree_seq.h:420
iterator_base(const btree_seq *t, size_type pos)
Pointing to specific place in the tree.
Definition: btree_seq.h:303
const_reference back() const
Returns a constant reference to the last element.
Definition: btree_seq.h:595
iterator erase(const_iterator pos)
Compatible function for erasing one element.
Definition: btree_seq.h:753
void shrink_to_fit()
Function does nothing (compatibility with std::vector).
Definition: btree_seq.h:982
pointer __get_null_pointer() const
Returns null pointer.
Definition: btree_seq.h:406
A::difference_type diff_type
Signed integer type, ptr_diff_t (int).
Definition: btree_seq.h:81
void emplace_back(Args &&...args)
Constructs an element at the end of the container and passes args to its constructor. (C++11)
Definition: btree_seq.h:839
void split_right(btree_seq< T, L, M, A > &that, size_type pos)
Fast split, leaving right piece in that container.
void swap(btree_seq< T, L, M, A > &that)
Swaps contents of two containers.
A::const_pointer const_pointer
Constant pointer type, const T*.
Definition: btree_seq.h:75
iterator_base operator++(int)
Postincrement.
Definition: btree_seq.h:388
bool operator>=(const btree_seq< T, L, M, A > &x, const btree_seq< T, L, M, A > &y)
Lexicographical comparison.
Definition: btree_seq.h:1012
bool operator!=(const iterator_base< T2 > &that) const
Comparison.
Definition: btree_seq.h:360
bool operator!=(const btree_seq< T, L, M, A > &x, const btree_seq< T, L, M, A > &y)
Inequality of size or any elements.
Definition: btree_seq.h:1023
void pop_back()
Removes the last element.
Definition: btree_seq.h:782
void reserve(size_type n)
Function does nothing (compatibility with std::vector).
Definition: btree_seq.h:980
iterator_base< const T > const_iterator
Constant forward random-access iterator.
Definition: btree_seq.h:409
size_type size() const
Number of elements in container.
Definition: btree_seq.h:567
btree_seq & operator=(const btree_seq< T, L, M, A > &that)
Assign content.
Definition: btree_seq.h:854
iterator_base & operator++()
Preincrement.
Definition: btree_seq.h:384
size_type get_position() const
Returns current position.
Definition: btree_seq.h:402
size_type __leaf_size()
Returns size of leaf node of the tree (profile, RTTI).
Definition: btree_seq.h:978
std::random_access_iterator_tag iterator_category
Random access iterator category.
Definition: btree_seq.h:270
void resize(size_type n, const value_type &val=value_type())
Resize container so that it contains n elements.
void assign(std::initializer_list< value_type > il)
assign with initializer_list (C++11)
Definition: btree_seq.h:950
iterator end()
Return constant iterator to end.
Definition: btree_seq.h:511
A::pointer pointer
Pointer type, T*.
Definition: btree_seq.h:73
iterator insert(const_iterator pos, size_type n, const value_type &val)
Compatible function for inserting n copies of an element.
Definition: btree_seq.h:663
void insert(size_type pos, const value_type &val)
Native function for inserting a single element.
Definition: btree_seq.h:623
std::reverse_iterator< iterator > reverse_iterator
Modifying reverse random-access iterator.
Definition: btree_seq.h:415
iterator emplace(const_iterator pos, Args &&...args)
Constructs an element at the given position (C++11)
Definition: btree_seq.h:823
size_type __elements_in_leaf()
Returns M (third parameter of the template) (profile, RTTI).
Definition: btree_seq.h:974
btree_seq(Iterator first, Iterator last, const allocator_type &alloc=allocator_type())
Range constructor.
Definition: btree_seq.h:454
void emplace_front(Args &&...args)
Constructs an element at the beginning of the container and passes args to its constructor. (C++11)
Definition: btree_seq.h:832
const_iterator end() const
Return constant iterator to end.
Definition: btree_seq.h:499
pointer operator->() const
Dereferencing.
Definition: btree_seq.h:349
std::iterator< std::random_access_iterator_tag, TT >::difference_type difference_type
ptrdiff_t (int).
Definition: btree_seq.h:278
A::size_type size_type
Unsigned integer type, size_t (unsigned int).
Definition: btree_seq.h:77
iterator_base operator-(difference_type n) const
Decrease position by n.
Definition: btree_seq.h:399
const_iterator begin() const
Return constant iterator to beginning.
Definition: btree_seq.h:496
iterator insert(const_iterator pos, InputIterator first, InputIterator last)
Compatible function for inserting a range of elements.
Definition: btree_seq.h:678
std::iterator< std::random_access_iterator_tag, TT >::reference reference
T& or const T&.
Definition: btree_seq.h:282
allocator_type get_allocator() const
Returns allocator.
Definition: btree_seq.h:984
iterator_base operator+(difference_type n) const
Increase position by n.
Definition: btree_seq.h:396
void erase(size_type first, size_type last)
Native function for erasing elements.
iterator_base & operator=(const iterator_base< T2 > &that)
Conversion from iterator to const_iterator.
Definition: btree_seq.h:338
iterator erase(const_iterator first, const_iterator last)
Compatible function for erasing elements.
Definition: btree_seq.h:766
iterator_base & operator--()
Predecrement.
Definition: btree_seq.h:386
std::iterator< std::random_access_iterator_tag, TT >::value_type value_type
T or const T.
Definition: btree_seq.h:274
btree_seq(size_type n, const value_type &val, const allocator_type &alloc=allocator_type())
Fill constructor.
Definition: btree_seq.h:441
reference front()
Returns a reference to the first element.
Definition: btree_seq.h:586
const_reference front() const
Returns a constnt reference to the first element.
Definition: btree_seq.h:589
bool operator>=(const iterator_base< T2 > &that) const
Comparison.
Definition: btree_seq.h:372
const_reverse_iterator crend() const
Return constant reverse iterator to reverse end.
Definition: btree_seq.h:523
void push_back(const value_type &val)
Adds element to the end of the sequence.
Definition: btree_seq.h:774
reference operator[](size_type pos)
Access to element.
Definition: btree_seq.h:547
bool operator==(const iterator_base< T2 > &that) const
Comparison.
Definition: btree_seq.h:356
iterator_base(const iterator_base< T2 > &that)
Constructor for conversion from iterator to const_iterator.
Definition: btree_seq.h:316
iterator iterator_at(size_type pos)
Return iterator to a given index.
Definition: btree_seq.h:532
const_reverse_iterator crbegin() const
Return constant reverse iterator to reverse beginning.
Definition: btree_seq.h:520
iterator insert(const_iterator pos, std::initializer_list< value_type > il)
Compatible inserting of elements using initializer_list (C++11)
Definition: btree_seq.h:719
const_reverse_iterator rbegin() const
Return constant reverse iterator to reverse beginning.
Definition: btree_seq.h:514
const_iterator citerator_at(size_type pos) const
Return constant iterator to a given index.
Definition: btree_seq.h:535
reference back()
Returns a reference to the last element.
Definition: btree_seq.h:592
const_reference at(size_type pos) const
Constant access to element with range check.
Definition: btree_seq.h:580
void fill(size_type pos, size_type repetition, const value_type &val)
Native function for inserting n copies of an element.
Definition: btree_seq.h:732
bool empty() const
Returns true if the container contains no elements.
Definition: btree_seq.h:597
const_iterator cbegin() const
Return constant iterator to beginning.
Definition: btree_seq.h:502
void push_front(value_type &&val)
Creates the element at the beginning of container and leaves val with undefined state. (C++11)
Definition: btree_seq.h:796
difference_type operator-(const iterator_base< T2 > &that) const
Comparison.
Definition: btree_seq.h:380
btree_seq(btree_seq< T, L, M, A > &&that, const allocator_type &alloc=allocator_type())
Move constructor (C++11)
Definition: btree_seq.h:467
The fast sequence container, which behaves like std::vector takes O(log(N)) to insert/delete elements...
Definition: btree_seq.h:61
size_type __branch_size()
Returns size of inner node of the tree (profile, RTTI).
Definition: btree_seq.h:976
~btree_seq()
Destructor.
Definition: btree_seq.h:489
reference operator[](difference_type n) const
Getting arbitary element.
Definition: btree_seq.h:351
void concatenate_left(btree_seq< T, L, M, A > &that)
Fast concatenate two sequences (that sequence to the left).
std::iterator< std::random_access_iterator_tag, TT >::pointer pointer
T* or const T*.
Definition: btree_seq.h:286
bool operator==(const btree_seq< T, L, M, A > &x, const btree_seq< T, L, M, A > &y)
Equality of size and all elements.
Definition: btree_seq.h:1017
const_reverse_iterator rend() const
Return constant reverse iterator to reverse end.
Definition: btree_seq.h:517
iterator_base & operator=(const iterator_base &that)
Operator = for the same type.
Definition: btree_seq.h:325
bool operator>(const iterator_base< T2 > &that) const
Comparison.
Definition: btree_seq.h:364
iterator_base & operator-=(difference_type n)
Decrease position by n.
Definition: btree_seq.h:394
void insert(size_type pos, std::initializer_list< value_type > il)
Native inserting of elements using initializer_list (C++11)
Definition: btree_seq.h:710
iterator_base< T > iterator
Modifying forward random-access iterator.
Definition: btree_seq.h:411
iterator_base(const iterator_base &that)
Copy constructor for the same type.
Definition: btree_seq.h:306
const_iterator cend() const
Return constant iterator to end.
Definition: btree_seq.h:505
void __output(output_stream &o, const char *comm="")
Output the contents of container into the stream (debug).
reference operator*() const
Dereferencing.
Definition: btree_seq.h:347
const btree_seq * get_container() const
Returns current container.
Definition: btree_seq.h:404
void clear()
Erases all contents of the container.
Definition: btree_seq.h:867
void swap(btree_seq< T, L, M, A > &first, btree_seq< T, L, M, A > &second)
Swap contents of two containers.
Definition: btree_seq.h:990
void assign(size_type n, const value_type &val)
Replaces the whole contents with n copies of val.
A::value_type value_type
Value type, T (the first template parameter).
Definition: btree_seq.h:67
reverse_iterator rbegin()
Return reverse iterator to reverse beginning.
Definition: btree_seq.h:526
btree_seq(const btree_seq< T, L, M, A > &that)
Copy constructor.
Definition: btree_seq.h:428
iterator_base & operator+=(difference_type n)
Increase position by n.
Definition: btree_seq.h:392
std::reverse_iterator< const_iterator > const_reverse_iterator
Constant reverse random-access iterator.
Definition: btree_seq.h:413
void concatenate_right(btree_seq< T, L, M, A > &that)
Fast concatenate two sequences (that sequence to the right).
btree_seq(std::initializer_list< value_type > il, const allocator_type &alloc=allocator_type())
Initializer list constructor (C++11)
Definition: btree_seq.h:480
void assign(InputIterator first, InputIterator last)
Replaces the whole contents with a range.
Definition: btree_seq.h:880
reference at(size_type pos)
Access to element with range check.
Definition: btree_seq.h:572
iterator begin()
Return iterator to beginning.
Definition: btree_seq.h:508
iterator insert(const_iterator pos, value_type &&val)
Compatible insertion of rvalue (C++11)
Definition: btree_seq.h:700