18 #if __cplusplus >= 201103L
20 #include <initializer_list>
31 namespace ___alexkupri_helpers
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; };
60 template <
typename T,
int L=30,
int M=60,
typename A=std::allocator<T> >
91 struct Branch:
public Node
97 struct Leaf:
public Node
102 typedef typename allocator_type::template rebind<Branch>::other Branch_alloc_type;
103 typedef typename allocator_type::template rebind<Leaf>::other Leaf_alloc_type;
105 Branch_alloc_type branch_alloc;
106 Leaf_alloc_type leaf_alloc;
113 template <
class InputIterator>
115 std::random_access_iterator_tag);
116 template <
class InputIterator>
118 std::input_iterator_tag);
119 template <
class InputIterator>
121 std::input_iterator_tag){
return limit+1;}
122 template <
class InputIterator>
124 std::random_access_iterator_tag){
return last-first;}
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);
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);
145 static size_type find_child(Branch *b,Node* c);
148 void increase_depth(Branch *new_branch);
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);
159 void advanced_sew_together(Leaf *last_leaf,
size_type pos);
163 void undo_preparing_to_insert
166 template <
class InputIterator>
167 Leaf* start_inserting(
size_type &pos,InputIterator &first,InputIterator last);
169 template <
class InputIterator>
170 Leaf* insert_whole_leaves(
size_type startpos,
size_type &pos,InputIterator first,InputIterator last,Leaf *last_leaf);
177 typedef std::random_access_iterator_tag iterator_category;
179 typename std::iterator<std::random_access_iterator_tag, T>::value_type
182 typename std::iterator<std::random_access_iterator_tag, T>::difference_type
185 typename std::iterator<std::random_access_iterator_tag, T>::reference
188 typename std::iterator<std::random_access_iterator_tag, T>::pointer
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; }
200 {
return static_cast<diff_type>(j)-static_cast<diff_type>(that.j);}
203 template<
typename Action>
211 erase_helper(
btree_seq &akaaka):last_leaf(0),leaves(0),aka(akaaka){}
213 bool shift_array(){
return true;}
215 Leaf *get_last_leaf(){
return last_leaf;}
224 visitor_helper(V &vv):v(vv),iters(0){};
226 bool shift_array(){
return false;}
234 template <
class Integer>
235 void impl_insert(
size_type pos,Integer n,Integer val,___alexkupri_helpers::my_true_type)
237 fill(pos,static_cast<size_type>(n),val);
239 template <
class InputIterator>
240 void impl_insert(
size_type pos,InputIterator first,InputIterator last,___alexkupri_helpers::my_false_type)
246 template <
class output_stream>
248 static void my_assert(
bool,
const char*);
265 template<
typename TT>
273 typename std::iterator<std::random_access_iterator_tag, TT>::value_type
277 typename std::iterator<std::random_access_iterator_tag, TT>::difference_type
281 typename std::iterator<std::random_access_iterator_tag, TT>::reference
285 typename std::iterator<std::random_access_iterator_tag, TT>::pointer
297 {
return (rel_idx<avail_ptr)?(elems+rel_idx):(rebase());}
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(){};
308 abs_idx(that.abs_idx),
310 avail_ptr(that.avail_ptr),
311 rel_idx(that.rel_idx),
313 idx_in_br(that.idx_in_br){};
315 template<
typename T2>
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;
337 template<
typename T2>
355 template<
typename T2>
359 template<
typename T2>
363 template<
typename T2>
367 template<
typename T2>
368 bool operator<(const iterator_base<T2>& that)
const
371 template<
typename T2>
375 template<
typename T2>
376 bool operator<=(const iterator_base<T2>& that)
const
379 template<
typename T2>
421 :T_alloc(alloc),branch_alloc(alloc),leaf_alloc(alloc),root(),count(0)
429 :T_alloc(that.T_alloc),branch_alloc(that.T_alloc),leaf_alloc(that.T_alloc),
443 :T_alloc(alloc),branch_alloc(alloc),leaf_alloc(alloc),root(),count(0)
453 template <
typename Iterator>
456 :T_alloc(alloc),branch_alloc(alloc),leaf_alloc(alloc),root(),count(0)
458 typename ___alexkupri_helpers::my_is_integer<Iterator>::__type is_int_type;
459 impl_insert(0,first,last,is_int_type);
461 #if __cplusplus >= 201103L
550 size_type found=depth?find_leaf(l,pos):pos;
562 size_type found=depth?find_leaf(l,pos):pos;
563 const T *ptr=l->elements;
626 size_type found=prepare_leaf_for_inserting(pos,1,l,0);
628 T_alloc.construct(l->elements+found,val);
630 undo_preparing_to_insert(pos,1,l,0,found);
640 template <
class InputIterator>
666 fill(position,n,val);
677 template<
class InputIterator>
680 typename ___alexkupri_helpers::my_is_integer<InputIterator>::__type is_int_type;
682 impl_insert(position,first,last,is_int_type);
685 #if __cplusplus >= 201103L
703 emplace(position,std::move(val));
712 insert(pos,il.begin(),il.end());
722 insert(position,il.begin(),il.end());
734 FillIterator first(&val,0),last(&val,repetition);
756 erase(position,position+1);
769 erase(first_position,last_position);
783 {
erase(count-1,count); }
788 #if __cplusplus >= 201103L
805 template <
class ...Args>
809 size_type found=prepare_leaf_for_inserting(pos,1,l,0);
811 T_alloc.construct(l->elements+found,std::forward<Args>(args)...);
813 undo_preparing_to_insert(pos,1,l,0,found);
822 template <
class ...Args>
826 emplace(position,std::forward<Args>(args)...);
831 template <
class ...Args>
834 emplace(0,std::forward<Args>(args)...);
838 template <
class... Args>
841 emplace(count,std::forward<Args>(args)...);
879 template <
class InputIterator>
880 void assign(InputIterator first,InputIterator last)
882 typename ___alexkupri_helpers::my_is_integer<InputIterator>::__type is_int_type;
884 impl_insert(0,first,last,is_int_type);
927 #if __cplusplus >= 201103L
950 void assign(std::initializer_list<value_type> il)
953 insert(0,il.begin(),il.end());
969 template <
class output_stream>
970 void __output(output_stream &o,
const char *comm=
"");
989 template <
typename T,
int L,
int M,
typename A>
996 template <
typename T,
int L,
int M,
typename A>
998 {
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
1001 template <
typename T,
int L,
int M,
typename A>
1006 template <
typename T,
int L,
int M,
typename A>
1011 template <
typename T,
int L,
int M,
typename A>
1016 template <
typename T,
int L,
int M,
typename A>
1022 template <
typename T,
int L,
int M,
typename A>
1027 #include "btree_seq2.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