STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
node.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/containers/btree/node.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2006 Roman Dementiev <[email protected]>
7  *
8  * Distributed under the Boost Software License, Version 1.0.
9  * (See accompanying file LICENSE_1_0.txt or copy at
10  * http://www.boost.org/LICENSE_1_0.txt)
11  **************************************************************************/
12 
13 #ifndef STXXL_CONTAINERS_BTREE_NODE_HEADER
14 #define STXXL_CONTAINERS_BTREE_NODE_HEADER
15 
18 
19 
21 
22 namespace btree {
23 
24 template <class NodeType, class BTreeType>
25 class node_cache;
26 
27 template <class KeyType_, class KeyCmp_, unsigned RawSize_, class BTreeType>
28 class normal_node : private noncopyable
29 {
30 public:
32 
33  friend class node_cache<SelfType, BTreeType>;
34 
35  typedef KeyType_ key_type;
36  typedef KeyCmp_ key_compare;
37 
38  enum {
39  raw_size = RawSize_
40  };
44  typedef std::pair<key_type, bid_type> value_type;
46  typedef const value_type& const_reference;
47 
48 
49  struct InfoType
50  {
52  unsigned cur_size;
53  };
55 
56  enum {
57  nelements = block_type::size - 1,
58  max_size = nelements,
59  min_size = nelements / 2
60  };
63 
64  typedef BTreeType btree_type;
65  typedef typename btree_type::size_type size_type;
66  typedef typename btree_type::iterator iterator;
67  typedef typename btree_type::const_iterator const_iterator;
68 
69  typedef typename btree_type::value_type btree_value_type;
70  typedef typename btree_type::leaf_bid_type leaf_bid_type;
71  typedef typename btree_type::leaf_type leaf_type;
72 
74 
75 private:
76  struct value_compare : public std::binary_function<value_type, value_type, bool>
77  {
79 
80  value_compare(key_compare c) : comp(c) { }
81 
82  bool operator () (const value_type& x, const value_type& y) const
83  {
84  return comp(x.first, y.first);
85  }
86  };
87 
92 
93 
94  std::pair<key_type, bid_type> insert(const std::pair<key_type, bid_type>& splitter,
95  const block_iterator& place2insert)
96  {
97  std::pair<key_type, bid_type> result(key_compare::max_value(), bid_type());
98 
99  // splitter != *place2insert
100  assert(vcmp_(*place2insert, splitter) || vcmp_(splitter, *place2insert));
101 
102  block_iterator cur = block_->begin() + size() - 1;
103  for ( ; cur >= place2insert; --cur)
104  *(cur + 1) = *cur;
105  // copy elements to make space for the new element
106 
107  *place2insert = splitter; // insert
108 
109  ++(block_->info.cur_size);
110 
111  if (size() > max_nelements()) // overflow! need to split
112  {
113  STXXL_VERBOSE1("btree::normal_node::insert overflow happened, splitting");
114 
115  bid_type NewBid;
116  btree_->node_cache_.get_new_node(NewBid); // new (left) node
117  normal_node* NewNode = btree_->node_cache_.get_node(NewBid, true);
118  assert(NewNode);
119 
120  const unsigned end_of_smaller_part = size() / 2;
121 
122  result.first = ((*block_)[end_of_smaller_part - 1]).first;
123  result.second = NewBid;
124 
125 
126  const unsigned old_size = size();
127  // copy the smaller part
128  std::copy(block_->begin(), block_->begin() + end_of_smaller_part, NewNode->block_->begin());
129  NewNode->block_->info.cur_size = end_of_smaller_part;
130  // copy the larger part
131  std::copy(block_->begin() + end_of_smaller_part,
132  block_->begin() + old_size, block_->begin());
133  block_->info.cur_size = old_size - end_of_smaller_part;
134  assert(size() + NewNode->size() == old_size);
135 
136  btree_->node_cache_.unfix_node(NewBid);
137 
138  STXXL_VERBOSE1("btree::normal_node split leaf " << this
139  << " splitter: " << result.first);
140  }
141 
142  return result;
143  }
144 
145  template <class CacheType>
146  void fuse_or_balance(block_iterator UIt, CacheType& cache_)
147  {
148  typedef typename CacheType::node_type local_node_type;
149  typedef typename local_node_type::bid_type local_bid_type;
150 
151  block_iterator leftIt, rightIt;
152  if (UIt == (block_->begin() + size() - 1)) // UIt is the last entry in the root
153  {
154  assert(UIt != block_->begin());
155  rightIt = UIt;
156  leftIt = --UIt;
157  }
158  else
159  {
160  leftIt = UIt;
161  rightIt = ++UIt;
162  assert(rightIt != (block_->begin() + size()));
163  }
164 
165  // now fuse or balance nodes pointed by leftIt and rightIt
166  local_bid_type LeftBid = (local_bid_type)leftIt->second;
167  local_bid_type RightBid = (local_bid_type)rightIt->second;
168  local_node_type* LeftNode = cache_.get_node(LeftBid, true);
169  local_node_type* RightNode = cache_.get_node(RightBid, true);
170 
171  const unsigned TotalSize = LeftNode->size() + RightNode->size();
172  if (TotalSize <= RightNode->max_nelements())
173  {
174  // fuse
175  RightNode->fuse(*LeftNode); // add the content of LeftNode to RightNode
176 
177  cache_.unfix_node(RightBid);
178  cache_.delete_node(LeftBid); // 'delete_node' unfixes LeftBid also
179 
180  std::copy(leftIt + 1, block_->begin() + size(), leftIt); // delete left BID from the root
181  --(block_->info.cur_size);
182  }
183  else
184  {
185  // balance
186 
187  key_type NewSplitter = RightNode->balance(*LeftNode);
188 
189 
190  leftIt->first = NewSplitter; // change key
191  assert(vcmp_(*leftIt, *rightIt));
192 
193  cache_.unfix_node(LeftBid);
194  cache_.unfix_node(RightBid);
195  }
196  }
197 
198 public:
199  virtual ~normal_node()
200  {
201  delete block_;
202  }
203 
205  key_compare cmp) :
206  block_(new block_type),
207  btree_(btree__),
208  cmp_(cmp),
209  vcmp_(cmp)
210  {
211  assert(min_nelements() >= 2);
212  assert(2 * min_nelements() - 1 <= max_nelements());
213  assert(max_nelements() <= nelements);
214  assert(unsigned(block_type::size) >= nelements + 1); // extra space for an overflow
215  }
216 
218  {
219  return *block_;
220  }
221 
222  bool overflows() const { return block_->info.cur_size > max_nelements(); }
223  bool underflows() const { return block_->info.cur_size < min_nelements(); }
224 
225  unsigned max_nelements() const { return max_size; }
226  unsigned min_nelements() const { return min_size; }
227 
228  /*
229  template <class InputIterator>
230  normal_node(InputIterator begin_, InputIterator end_,
231  btree_type * btree__,
232  key_compare cmp):
233  block_(new block_type),
234  btree_(btree__),
235  cmp_(cmp),
236  vcmp_(cmp)
237  {
238  assert(min_nelements() >=2);
239  assert(2*min_nelements() - 1 <= max_nelements());
240  assert(max_nelements() <= nelements);
241  assert(unsigned(block_type::size) >= nelements +1); // extra space for an overflow
242 
243  unsigned new_size = end_ - begin_;
244  assert(new_size <= max_nelements());
245  assert(new_size >= min_nelements());
246 
247  std::copy(begin_,end_,block_->begin());
248  assert(stxxl::is_sorted(block_->begin(),block_->begin() + new_size, vcmp_));
249  block_->info.cur_size = new_size;
250  }*/
251 
252  unsigned size() const
253  {
254  return block_->info.cur_size;
255  }
256 
257  bid_type my_bid() const
258  {
259  return block_->info.me;
260  }
261 
262  void save()
263  {
264  request_ptr req = block_->write(my_bid());
265  req->wait();
266  }
267 
269  {
270  request_ptr req = block_->read(bid);
271  req->wait();
272  assert(bid == my_bid());
273  return req;
274  }
275 
277  {
278  return block_->read(bid);
279  }
280 
281  void init(const bid_type& my_bid_)
282  {
283  block_->info.me = my_bid_;
284  block_->info.cur_size = 0;
285  }
286 
287  reference operator [] (int i)
288  {
289  return (*block_)[i];
290  }
291 
292  const_reference operator [] (int i) const
293  {
294  return (*block_)[i];
295  }
296 
298  {
299  return (*block_)[size() - 1];
300  }
301 
303  {
304  return *(block_->begin());
305  }
306 
308  {
309  return (*block_)[size() - 1];
310  }
311 
313  {
314  return *(block_->begin());
315  }
316 
317 
318  std::pair<iterator, bool> insert(
319  const btree_value_type& x,
320  unsigned height,
321  std::pair<key_type, bid_type>& splitter)
322  {
323  assert(size() <= max_nelements());
324  splitter.first = key_compare::max_value();
325 
326  value_type Key2Search(x.first, bid_type());
327  block_iterator it =
328  std::lower_bound(block_->begin(), block_->begin() + size(), Key2Search, vcmp_);
329 
330  assert(it != (block_->begin() + size()));
331 
332  bid_type found_bid = it->second;
333  STXXL_UNUSED(found_bid);
334 
335  if (height == 2) // found_bid points to a leaf
336  {
337  STXXL_VERBOSE1("btree::normal_node Inserting new value into a leaf");
338  leaf_type* Leaf = btree_->leaf_cache_.get_node((leaf_bid_type)it->second, true);
339  assert(Leaf);
340  std::pair<key_type, leaf_bid_type> BotSplitter;
341  std::pair<iterator, bool> result = Leaf->insert(x, BotSplitter);
342  btree_->leaf_cache_.unfix_node((leaf_bid_type)it->second);
343  //if(key_compare::max_value() == BotSplitter.first)
344  if (!(cmp_(key_compare::max_value(), BotSplitter.first) ||
345  cmp_(BotSplitter.first, key_compare::max_value())))
346  return result;
347  // no overflow/splitting happened
348 
349  STXXL_VERBOSE1("btree::normal_node Inserting new value in *this");
350 
351  splitter = insert(std::make_pair(BotSplitter.first, bid_type(BotSplitter.second)), it);
352 
353  return result;
354  }
355  else
356  { // found_bid points to a node
357  STXXL_VERBOSE1("btree::normal_node Inserting new value into a node");
358  node_type* Node = btree_->node_cache_.get_node((node_bid_type)it->second, true);
359  assert(Node);
360  std::pair<key_type, node_bid_type> BotSplitter;
361  std::pair<iterator, bool> result = Node->insert(x, height - 1, BotSplitter);
362  btree_->node_cache_.unfix_node((node_bid_type)it->second);
363  //if(key_compare::max_value() == BotSplitter.first)
364  if (!(cmp_(key_compare::max_value(), BotSplitter.first) ||
365  cmp_(BotSplitter.first, key_compare::max_value())))
366  return result;
367  // no overflow/splitting happened
368 
369  STXXL_VERBOSE1("btree::normal_node Inserting new value in *this");
370 
371  splitter = insert(BotSplitter, it);
372 
373  return result;
374  }
375  }
376 
377  iterator begin(unsigned height)
378  {
379  bid_type FirstBid = block_->begin()->second;
380  if (height == 2) // FirstBid points to a leaf
381  {
382  assert(size() > 1);
383  STXXL_VERBOSE1("btree::node retrieveing begin() from the first leaf");
384  leaf_type* Leaf = btree_->leaf_cache_.get_node((leaf_bid_type)FirstBid);
385  assert(Leaf);
386  return Leaf->begin();
387  }
388  else
389  { // FirstBid points to a node
390  STXXL_VERBOSE1("btree: retrieveing begin() from the first node");
391  node_type* Node = btree_->node_cache_.get_node((node_bid_type)FirstBid, true);
392  assert(Node);
393  iterator result = Node->begin(height - 1);
394  btree_->node_cache_.unfix_node((node_bid_type)FirstBid);
395  return result;
396  }
397  }
398 
399  const_iterator begin(unsigned height) const
400  {
401  bid_type FirstBid = block_->begin()->second;
402  if (height == 2) // FirstBid points to a leaf
403  {
404  assert(size() > 1);
405  STXXL_VERBOSE1("btree::node retrieveing begin() from the first leaf");
406  leaf_type const* Leaf = btree_->leaf_cache_.get_const_node((leaf_bid_type)FirstBid);
407  assert(Leaf);
408  return Leaf->begin();
409  }
410  else
411  { // FirstBid points to a node
412  STXXL_VERBOSE1("btree: retrieveing begin() from the first node");
413  node_type const* Node = btree_->node_cache_.get_const_node((node_bid_type)FirstBid, true);
414  assert(Node);
415  const_iterator result = Node->begin(height - 1);
416  btree_->node_cache_.unfix_node((node_bid_type)FirstBid);
417  return result;
418  }
419  }
420 
421  iterator find(const key_type& k, unsigned height)
422  {
423  value_type Key2Search(k, bid_type());
424 
425  block_iterator it =
426  std::lower_bound(block_->begin(), block_->begin() + size(), Key2Search, vcmp_);
427 
428  assert(it != (block_->begin() + size()));
429 
430  bid_type found_bid = it->second;
431 
432  if (height == 2) // found_bid points to a leaf
433  {
434  STXXL_VERBOSE1("Searching in a leaf");
435  leaf_type* Leaf = btree_->leaf_cache_.get_node((leaf_bid_type)found_bid, true);
436  assert(Leaf);
437  iterator result = Leaf->find(k);
438  btree_->leaf_cache_.unfix_node((leaf_bid_type)found_bid);
439 
440  return result;
441  }
442 
443  // found_bid points to a node
444  STXXL_VERBOSE1("Searching in a node");
445  node_type* Node = btree_->node_cache_.get_node((node_bid_type)found_bid, true);
446  assert(Node);
447  iterator result = Node->find(k, height - 1);
448  btree_->node_cache_.unfix_node((node_bid_type)found_bid);
449 
450  return result;
451  }
452 
453  const_iterator find(const key_type& k, unsigned height) const
454  {
455  value_type Key2Search(k, bid_type());
456 
457  block_iterator it =
458  std::lower_bound(block_->begin(), block_->begin() + size(), Key2Search, vcmp_);
459 
460  assert(it != (block_->begin() + size()));
461 
462  bid_type found_bid = it->second;
463 
464  if (height == 2) // found_bid points to a leaf
465  {
466  STXXL_VERBOSE1("Searching in a leaf");
467  leaf_type const* Leaf = btree_->leaf_cache_.get_const_node((leaf_bid_type)found_bid, true);
468  assert(Leaf);
469  const_iterator result = Leaf->find(k);
470  btree_->leaf_cache_.unfix_node((leaf_bid_type)found_bid);
471 
472  return result;
473  }
474 
475  // found_bid points to a node
476  STXXL_VERBOSE1("Searching in a node");
477  node_type const* Node = btree_->node_cache_.get_const_node((node_bid_type)found_bid, true);
478  assert(Node);
479  const_iterator result = Node->find(k, height - 1);
480  btree_->node_cache_.unfix_node((node_bid_type)found_bid);
481 
482  return result;
483  }
484 
485  iterator lower_bound(const key_type& k, unsigned height)
486  {
487  value_type Key2Search(k, bid_type());
488  assert(!vcmp_(back(), Key2Search));
489  block_iterator it =
490  std::lower_bound(block_->begin(), block_->begin() + size(), Key2Search, vcmp_);
491 
492  assert(it != (block_->begin() + size()));
493 
494  bid_type found_bid = it->second;
495 
496  if (height == 2) // found_bid points to a leaf
497  {
498  STXXL_VERBOSE1("Searching lower bound in a leaf");
499  leaf_type* Leaf = btree_->leaf_cache_.get_node((leaf_bid_type)found_bid, true);
500  assert(Leaf);
501  iterator result = Leaf->lower_bound(k);
502  btree_->leaf_cache_.unfix_node((leaf_bid_type)found_bid);
503 
504  return result;
505  }
506 
507  // found_bid points to a node
508  STXXL_VERBOSE1("Searching lower bound in a node");
509  node_type* Node = btree_->node_cache_.get_node((node_bid_type)found_bid, true);
510  assert(Node);
511  iterator result = Node->lower_bound(k, height - 1);
512  btree_->node_cache_.unfix_node((node_bid_type)found_bid);
513 
514  return result;
515  }
516 
517  const_iterator lower_bound(const key_type& k, unsigned height) const
518  {
519  value_type Key2Search(k, bid_type());
520  assert(!vcmp_(back(), Key2Search));
521  block_iterator it =
522  std::lower_bound(block_->begin(), block_->begin() + size(), Key2Search, vcmp_);
523 
524  assert(it != (block_->begin() + size()));
525 
526  bid_type found_bid = it->second;
527 
528  if (height == 2) // found_bid points to a leaf
529  {
530  STXXL_VERBOSE1("Searching lower bound in a leaf");
531  leaf_type const* Leaf = btree_->leaf_cache_.get_const_node((leaf_bid_type)found_bid, true);
532  assert(Leaf);
533  const_iterator result = Leaf->lower_bound(k);
534  btree_->leaf_cache_.unfix_node((leaf_bid_type)found_bid);
535 
536  return result;
537  }
538 
539  // found_bid points to a node
540  STXXL_VERBOSE1("Searching lower bound in a node");
541  node_type const* Node = btree_->node_cache_.get_const_node((node_bid_type)found_bid, true);
542  assert(Node);
543  const_iterator result = Node->lower_bound(k, height - 1);
544  btree_->node_cache_.unfix_node((node_bid_type)found_bid);
545 
546  return result;
547  }
548 
549  iterator upper_bound(const key_type& k, unsigned height)
550  {
551  value_type Key2Search(k, bid_type());
552  assert(vcmp_(Key2Search, back()));
553  block_iterator it =
554  std::upper_bound(block_->begin(), block_->begin() + size(), Key2Search, vcmp_);
555 
556  assert(it != (block_->begin() + size()));
557 
558  bid_type found_bid = it->second;
559 
560  if (height == 2) // found_bid points to a leaf
561  {
562  STXXL_VERBOSE1("Searching upper bound in a leaf");
563  leaf_type* Leaf = btree_->leaf_cache_.get_node((leaf_bid_type)found_bid, true);
564  assert(Leaf);
565  iterator result = Leaf->upper_bound(k);
566  btree_->leaf_cache_.unfix_node((leaf_bid_type)found_bid);
567 
568  return result;
569  }
570 
571  // found_bid points to a node
572  STXXL_VERBOSE1("Searching upper bound in a node");
573  node_type* Node = btree_->node_cache_.get_node((node_bid_type)found_bid, true);
574  assert(Node);
575  iterator result = Node->upper_bound(k, height - 1);
576  btree_->node_cache_.unfix_node((node_bid_type)found_bid);
577 
578  return result;
579  }
580 
581  const_iterator upper_bound(const key_type& k, unsigned height) const
582  {
583  value_type Key2Search(k, bid_type());
584  assert(vcmp_(Key2Search, back()));
585  block_iterator it =
586  std::upper_bound(block_->begin(), block_->begin() + size(), Key2Search, vcmp_);
587 
588  assert(it != (block_->begin() + size()));
589 
590  bid_type found_bid = it->second;
591 
592  if (height == 2) // found_bid points to a leaf
593  {
594  STXXL_VERBOSE1("Searching upper bound in a leaf");
595  leaf_type const* Leaf = btree_->leaf_cache_.get_const_node((leaf_bid_type)found_bid, true);
596  assert(Leaf);
597  const_iterator result = Leaf->upper_bound(k);
598  btree_->leaf_cache_.unfix_node((leaf_bid_type)found_bid);
599 
600  return result;
601  }
602 
603  // found_bid points to a node
604  STXXL_VERBOSE1("Searching upper bound in a node");
605  node_type const* Node = btree_->node_cache_.get_const_node((node_bid_type)found_bid, true);
606  assert(Node);
607  const_iterator result = Node->upper_bound(k, height - 1);
608  btree_->node_cache_.unfix_node((node_bid_type)found_bid);
609 
610  return result;
611  }
612 
613  void fuse(const normal_node& Src)
614  {
615  assert(vcmp_(Src.back(), front()));
616  const unsigned SrcSize = Src.size();
617 
618  block_iterator cur = block_->begin() + size() - 1;
619  block_const_iterator begin = block_->begin();
620 
621  for ( ; cur >= begin; --cur)
622  *(cur + SrcSize) = *cur;
623  // move elements to make space for Src elements
624 
625  // copy Src to *this leaf
626  std::copy(Src.block_->begin(), Src.block_->begin() + SrcSize, block_->begin());
627 
628  block_->info.cur_size += SrcSize;
629  }
630 
631 
633  {
634  const unsigned TotalSize = Left.size() + size();
635  unsigned newLeftSize = TotalSize / 2;
636  assert(newLeftSize <= Left.max_nelements());
637  assert(newLeftSize >= Left.min_nelements());
638  unsigned newRightSize = TotalSize - newLeftSize;
639  assert(newRightSize <= max_nelements());
640  assert(newRightSize >= min_nelements());
641 
642  assert(vcmp_(Left.back(), front()) || size() == 0);
643 
644  if (newLeftSize < Left.size())
645  {
646  const unsigned nEl2Move = Left.size() - newLeftSize; // #elements to move from Left to *this
647 
648  block_iterator cur = block_->begin() + size() - 1;
649  block_const_iterator begin = block_->begin();
650 
651  for ( ; cur >= begin; --cur)
652  *(cur + nEl2Move) = *cur;
653  // move elements to make space for Src elements
654 
655  // copy Left to *this leaf
656  std::copy(Left.block_->begin() + newLeftSize,
657  Left.block_->begin() + Left.size(), block_->begin());
658  }
659  else
660  {
661  assert(newRightSize < size());
662 
663  const unsigned nEl2Move = size() - newRightSize; // #elements to move from *this to Left
664 
665  // copy *this to Left
666  std::copy(block_->begin(),
667  block_->begin() + nEl2Move, Left.block_->begin() + Left.size());
668  // move elements in *this
669  std::copy(block_->begin() + nEl2Move,
670  block_->begin() + size(), block_->begin());
671  }
672 
673  block_->info.cur_size = newRightSize; // update size
674  Left.block_->info.cur_size = newLeftSize; // update size
675 
676  return Left.back().first;
677  }
678 
679  size_type erase(const key_type& k, unsigned height)
680  {
681  value_type Key2Search(k, bid_type());
682 
683  block_iterator it =
684  std::lower_bound(block_->begin(), block_->begin() + size(), Key2Search, vcmp_);
685 
686  assert(it != (block_->begin() + size()));
687 
688  bid_type found_bid = it->second;
689 
690  assert(size() >= 2);
691 
692  if (height == 2) // 'found_bid' points to a leaf
693  {
694  STXXL_VERBOSE1("btree::normal_node Deleting key from a leaf");
695  leaf_type* Leaf = btree_->leaf_cache_.get_node((leaf_bid_type)found_bid, true);
696  assert(Leaf);
697  size_type result = Leaf->erase(k);
698  btree_->leaf_cache_.unfix_node((leaf_bid_type)it->second);
699  if (!Leaf->underflows())
700  return result;
701  // no underflow or root has a special degree 1 (too few elements)
702 
703  STXXL_VERBOSE1("btree::normal_node Fusing or rebalancing a leaf");
704  fuse_or_balance(it, btree_->leaf_cache_);
705 
706  return result;
707  }
708 
709  // 'found_bid' points to a node
710  STXXL_VERBOSE1("btree::normal_node Deleting key from a node");
711  node_type* Node = btree_->node_cache_.get_node((node_bid_type)found_bid, true);
712  assert(Node);
713  size_type result = Node->erase(k, height - 1);
714  btree_->node_cache_.unfix_node((node_bid_type)found_bid);
715  if (!Node->underflows())
716  return result;
717  // no underflow happened
718 
719  STXXL_VERBOSE1("btree::normal_node Fusing or rebalancing a node");
720  fuse_or_balance(it, btree_->node_cache_);
721 
722  return result;
723  }
724 
725  void deallocate_children(unsigned height)
726  {
727  if (height == 2)
728  {
729  // we have children leaves here
730  block_const_iterator it = block().begin();
731  for ( ; it != block().begin() + size(); ++it)
732  {
733  // delete from leaf cache and deallocate bid
734  btree_->leaf_cache_.delete_node((leaf_bid_type)it->second);
735  }
736  }
737  else
738  {
739  block_const_iterator it = block().begin();
740  for ( ; it != block().begin() + size(); ++it)
741  {
742  node_type* Node = btree_->node_cache_.get_node((node_bid_type)it->second);
743  assert(Node);
744  Node->deallocate_children(height - 1);
745  // delete from node cache and deallocate bid
746  btree_->node_cache_.delete_node((node_bid_type)it->second);
747  }
748  }
749  }
750 
751  void push_back(const value_type& x)
752  {
753  (*this)[size()] = x;
754  ++(block_->info.cur_size);
755  }
756 };
757 
758 } // namespace btree
759 
760 
762 
763 
764 #endif // !STXXL_CONTAINERS_BTREE_NODE_HEADER
btree_type::value_type btree_value_type
Definition: node.h:69
std::pair< key_type, bid_type > insert(const std::pair< key_type, bid_type > &splitter, const block_iterator &place2insert)
Definition: node.h:94
virtual ~normal_node()
Definition: node.h:199
key_type balance(normal_node &Left)
Definition: node.h:632
SelfType node_type
Definition: node.h:43
BTreeType btree_type
Definition: node.h:64
void fuse_or_balance(block_iterator UIt, CacheType &cache_)
Definition: node.h:146
info_type info
Per block information element.
Definition: typed_block.h:180
bool underflows() const
Definition: node.h:223
btree_type::leaf_type leaf_type
Definition: node.h:71
btree_type::size_type size_type
Definition: node.h:65
bid_type node_bid_type
Definition: node.h:42
block_type & block()
Definition: node.h:217
unsigned min_nelements() const
Definition: node.h:226
key_compare cmp_
Definition: node.h:90
block_type::const_iterator block_const_iterator
Definition: node.h:62
block_type * block_
Definition: node.h:88
btree_type::iterator iterator
Definition: node.h:66
normal_node< KeyType_, KeyCmp_, RawSize_, BTreeType > SelfType
Definition: node.h:31
void fuse(const normal_node &Src)
Definition: node.h:613
request_ptr prefetch(const bid_type &bid)
Definition: node.h:276
reference back()
Definition: node.h:297
block_type::iterator block_iterator
Definition: node.h:61
iterator find(const key_type &k, unsigned height)
Definition: node.h:421
const_iterator upper_bound(const key_type &k, unsigned height) const
Definition: node.h:581
btree_type::const_iterator const_iterator
Definition: node.h:67
Block containing elements of fixed length.
Definition: typed_block.h:238
virtual void wait(bool measure_time=true)=0
Suspends calling thread until completion of the request.
unsigned max_nelements() const
Definition: node.h:225
BID< raw_size > bid_type
Definition: node.h:41
std::pair< iterator, bool > insert(const btree_value_type &x, unsigned height, std::pair< key_type, bid_type > &splitter)
Definition: node.h:318
const_pointer const_iterator
Definition: typed_block.h:250
btree_type::leaf_bid_type leaf_bid_type
Definition: node.h:70
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
void STXXL_UNUSED(const U &)
Definition: unused.h:23
normal_node(btree_type *btree__, key_compare cmp)
Definition: node.h:204
btree_type * btree_
Definition: node.h:89
iterator begin(unsigned height)
Definition: node.h:377
#define STXXL_VERBOSE1(x)
Definition: verbose.h:99
bid_type my_bid() const
Definition: node.h:257
node_cache< normal_node, btree_type > node_cache_type
Definition: node.h:73
size_type erase(const key_type &k, unsigned height)
Definition: node.h:679
reference front()
Definition: node.h:302
iterator begin()
Returns iterator pointing to the first element.
Definition: typed_block.h:93
bool overflows() const
Definition: node.h:222
const_iterator lower_bound(const key_type &k, unsigned height) const
Definition: node.h:517
value_compare vcmp_
Definition: node.h:91
const value_type & const_reference
Definition: node.h:46
const_reference back() const
Definition: node.h:307
void deallocate_children(unsigned height)
Definition: node.h:725
value_type & reference
Definition: node.h:45
unsigned size() const
Definition: node.h:252
const_iterator begin(unsigned height) const
Definition: node.h:399
iterator lower_bound(const key_type &k, unsigned height)
Definition: node.h:485
std::pair< key_type, bid_type > value_type
Definition: node.h:44
typed_block< raw_size, value_type, 0, InfoType > block_type
Definition: node.h:54
void push_back(const value_type &x)
Definition: node.h:751
request_ptr load(const bid_type &bid)
Definition: node.h:268
const_iterator find(const key_type &k, unsigned height) const
Definition: node.h:453
#define STXXL_END_NAMESPACE
Definition: namespace.h:17
const_reference front() const
Definition: node.h:312
void init(const bid_type &my_bid_)
Definition: node.h:281
iterator upper_bound(const key_type &k, unsigned height)
Definition: node.h:549