| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library index.btree; | 5 library index.b_plus_tree; |
| 6 | 6 |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * A simple B+Tree implementation. | 9 * A simple B+ tree (http://en.wikipedia.org/wiki/B+_tree) implementation. |
| 10 */ | 10 */ |
| 11 class BTree<K, V> { | 11 class BPlusTree<K, V> { |
| 12 /** | 12 /** |
| 13 * The [Comparator] to compare keys. | 13 * The [Comparator] to compare keys. |
| 14 */ | 14 */ |
| 15 final Comparator<K> _comparator; | 15 final Comparator<K> _comparator; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * The maximum number of keys in an index node. | 18 * The maximum number of keys in an index node. |
| 19 */ | 19 */ |
| 20 final int _maxIndexKeys; | 20 final int _maxIndexKeys; |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * The maximum number of keys in a leaf node. | 23 * The maximum number of keys in a leaf node. |
| 24 */ | 24 */ |
| 25 final int _maxLeafKeys; | 25 final int _maxLeafKeys; |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * The root node. | 28 * The root node. |
| 29 */ | 29 */ |
| 30 _Node<K, V> _root; | 30 _Node<K, V> _root; |
| 31 | 31 |
| 32 BTree(this._maxIndexKeys, this._maxLeafKeys, this._comparator) { | 32 BPlusTree(this._maxIndexKeys, this._maxLeafKeys, this._comparator) { |
| 33 _root = new _LeafNode(_maxLeafKeys, _comparator); | 33 _root = new _LeafNode(_maxLeafKeys, _comparator); |
| 34 } | 34 } |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * Returns the value for [key] or `null` if [key] is not in the tree. | 37 * Returns the value for [key] or `null` if [key] is not in the tree. |
| 38 */ | 38 */ |
| 39 V find(K key) { | 39 V find(K key) { |
| 40 return _root.find(key); | 40 return _root.find(key); |
| 41 } | 41 } |
| 42 | 42 |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 458 |
| 459 /** | 459 /** |
| 460 * A container with information about split during insert. | 460 * A container with information about split during insert. |
| 461 */ | 461 */ |
| 462 class _Split<K, V> { | 462 class _Split<K, V> { |
| 463 final K key; | 463 final K key; |
| 464 final _Node<K, V> left; | 464 final _Node<K, V> left; |
| 465 final _Node<K, V> right; | 465 final _Node<K, V> right; |
| 466 _Split(this.key, this.left, this.right); | 466 _Split(this.key, this.left, this.right); |
| 467 } | 467 } |
| OLD | NEW |