Skip to content

Commit

Permalink
<update> include_directories: include utils/include src
Browse files Browse the repository at this point in the history
  • Loading branch information
ByJuanDiego committed Mar 25, 2023
1 parent b661c09 commit b6ac748
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 36 deletions.
38 changes: 32 additions & 6 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.16)
project(b_plus_tree)

include_directories(utils/include src include)
set(CMAKE_CXX_STANDARD 20)

add_executable(b_plus_tree main.cpp include/node.hpp include/bplustree.hpp src/bplustree.cpp src/node.cpp utils/include/transaction.hpp utils/src/transaction.cpp)
add_executable(b_plus_tree src/main.cpp include/node.hpp include/bplustree.hpp src/bplustree.cpp src/node.cpp utils/include/transaction.hpp utils/src/transaction.cpp)
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ All the search operations returns an ```std::list<V>``` and are made on a $O(log
is the cost of traversing the leaf nodes and could be different depending on the type of search, and the logarithmic
function belongs to the cost of descending in the tree.

| Member Function | Optional Parameters |
|:----------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| ```search_below(K max, bool include_max)``` | the search returned ***do not include*** the superior limit for default, to include it, set the optional parameter ```include_max``` as ```true``` |
| ```search_above(K min, bool include_min)``` | the search returned ***do not include*** the inferior limit for default, to include it, set the optional parameter ```include_min``` as ```true``` |
| ```search_between(K min, K max, bool include_min, bool include_max)``` | the search returned ***includes*** both limits (inferior and superior) for default; to ***exclude*** one or both limits, set the ```include_min``` or ```include_max``` values to ```false``` depending on the desired semantic |
| Member Function | Optional Parameters |
|:--------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| ```search_below(K upper_bound, bool include_max)``` | the search returned ***do not include*** the superior limit for default, to include it, set the optional parameter ```include_max``` as ```true``` |
| ```search_above(K lower_bound, bool include_min)``` | the search returned ***do not include*** the inferior limit for default, to include it, set the optional parameter ```include_min``` as ```true``` |
| ```search_between(K lower_bound, K upper_bound, bool include_min, bool include_max)``` | the search returned ***includes*** both limits (inferior and superior) for default; to ***exclude*** one or both limits, set the ```include_min``` or ```include_max``` values to ```false``` depending on the desired semantic |

# Usage Cases

Expand All @@ -48,8 +48,8 @@ b_plus_tree<4, int, transaction *, decltype(greater), decltype(index)> bPlusTree
## Querying

```c++
int min {10}, max{97};
bool include_min {true}, include_max {false};
int min{10}, max{97};
bool include_min{true}, include_max{false};
for (const transaction *tx: bPlusTree.search_between(min, max, include_min, include_max)) {
std::cout << tx->to_string() << std::endl;
}
Expand Down
14 changes: 7 additions & 7 deletions include/bplustree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <queue>
#include <list>

#include "../src/node.cpp"
#include "node.cpp"

#ifndef MINIMUM_ORDER
#define MINIMUM_ORDER 3
Expand Down Expand Up @@ -112,14 +112,14 @@ class b_plus_tree {
/// Returns the records which index attribute are maxmimum
std::list<V> search_max();

/// Returns the records which index attribute are lesser than `max`
std::list<V> search_below(K max, bool include_max = false);
/// Returns the records which index attribute are lesser than `upper_bound`
std::list<V> search_below(K upper_bound, bool include_max = false);

/// Returns the records which index attribute are greater than `min`
std::list<V> search_above(K min, bool include_min = false);
/// Returns the records which index attribute are greater than `lower_bound`
std::list<V> search_above(K lower_bound, bool include_min = false);

/// Returns the records which index attribute are between `min` and `max`
std::list<V> search_between(K min, K max, bool include_min = true, bool include_max = true);
/// Returns the records which index attribute are between `lower_bound` and `upper_bound`
std::list<V> search_between(K lower_bound, K upper_bound, bool include_min = true, bool include_max = true);

/**
* Prints all the B+ Tree
Expand Down
22 changes: 11 additions & 11 deletions src/bplustree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Created by juandiego on 3/19/23.
//

#include "../include/bplustree.hpp"
#include "bplustree.hpp"

//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -229,11 +229,11 @@ std::list<V> b_plus_tree<M, K, V, Index, Greater>::search_max() {

template<int M, typename K, typename V, typename Index, typename Greater>
requires OrderConstraint<M>
std::list<V> b_plus_tree<M, K, V, Index, Greater>::search_below(K max, bool include_max) {
std::list<V> b_plus_tree<M, K, V, Index, Greater>::search_below(K upper_bound, bool include_max) {
std::list<V> search;
leaf_node<K, V> *leaf = search_node(root, max);
leaf_node<K, V> *leaf = search_node(root, upper_bound);
auto include_condition = ([&](K key) {
return include_max ? (!greater(key, max)) : (greater(max, key));
return include_max ? (!greater(key, upper_bound)) : (greater(upper_bound, key));
});

while (leaf) {
Expand All @@ -249,11 +249,11 @@ std::list<V> b_plus_tree<M, K, V, Index, Greater>::search_below(K max, bool incl

template<int M, typename K, typename V, typename Index, typename Greater>
requires OrderConstraint<M>
std::list<V> b_plus_tree<M, K, V, Index, Greater>::search_above(K min, bool include_min) {
std::list<V> b_plus_tree<M, K, V, Index, Greater>::search_above(K lower_bound, bool include_min) {
std::list<V> search;
leaf_node<K, V> *leaf = search_node(root, min);
leaf_node<K, V> *leaf = search_node(root, lower_bound);
auto include_condition = ([&](K key) {
return include_min ? (!greater(min, key)) : (greater(key, min));
return include_min ? (!greater(lower_bound, key)) : (greater(key, lower_bound));
});

while (leaf) {
Expand All @@ -269,14 +269,14 @@ std::list<V> b_plus_tree<M, K, V, Index, Greater>::search_above(K min, bool incl

template<int M, typename K, typename V, typename Index, typename Greater>
requires OrderConstraint<M>
std::list<V> b_plus_tree<M, K, V, Index, Greater>::search_between(K min, K max, bool include_min, bool include_max) {
std::list<V> b_plus_tree<M, K, V, Index, Greater>::search_between(K lower_bound, K upper_bound, bool include_min, bool include_max) {
std::list<V> search;
leaf_node<K, V> *leaf = search_node(root, min);
leaf_node<K, V> *leaf = search_node(root, lower_bound);
auto stop_condition = ([&](K key) -> bool {
return include_max ? (greater(key, max)) : (!greater(max, key));
return include_max ? (greater(key, upper_bound)) : (!greater(upper_bound, key));
});
auto include_condition = ([&](K key) -> bool {
return include_min ? (!greater(min, key)) : (greater(key, min));
return include_min ? (!greater(lower_bound, key)) : (greater(key, lower_bound));
});

while (leaf) {
Expand Down
4 changes: 2 additions & 2 deletions main.cpp → src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <fstream>
#include <iomanip>

#include "src/bplustree.cpp"
#include "utils/include/transaction.hpp"
#include "bplustree.cpp"
#include "transaction.hpp"

int main() {
auto index = [&](const transaction *tx) -> int { return tx->amount; };
Expand Down
2 changes: 1 addition & 1 deletion src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Created by juandiego on 3/19/23.
//

#include "../include/node.hpp"
#include "node.hpp"

//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion utils/src/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Created by juandiego on 3/22/23.
//

#include "../include/transaction.hpp"
#include "transaction.hpp"

//-----------------------------------------------------------------------------

Expand Down

0 comments on commit b6ac748

Please sign in to comment.