Skip to content

Instantly share code, notes, and snippets.

@likern
Last active September 5, 2023 18:17
Show Gist options
  • Save likern/6bd8a3d837247d0bb2886d0982f96bfe to your computer and use it in GitHub Desktop.
Save likern/6bd8a3d837247d0bb2886d0982f96bfe to your computer and use it in GitHub Desktop.
#define BPLUSTREE_TYPE BPlusTree<KeyType, ValueType, KeyComparator>
#define INDEX_TEMPLATE_ARGUMENTS template <typename KeyType, typename ValueType, typename KeyComparator>
// Main class providing the API for the Interactive B+ Tree.
INDEX_TEMPLATE_ARGUMENTS
class BPlusTree {
public:
using InternalPage = BPlusTreeInternalPage<KeyType, page_id_t, KeyComparator>;
using LeafPage = BPlusTreeLeafPage<KeyType, ValueType, KeyComparator>;
template <IndexPageKind kind>
using IndexPageOf = typename std::conditional<(kind == IndexPageKind::Internal), InternalPage, LeafPage>::type;
template <IndexPageKind kind>
using IndexPageValueOf = typename std::conditional<(kind == IndexPageKind::Internal), page_id_t, ValueType>::type;
template <TraverseWith mode>
using PageWithLock =
typename std::conditional<(mode == TraverseWith::ReadLocks), ReadPageGuard, WritePageGuard>::type;
/* Insert (key, value) pair into page if it's not full, otherwise return false */
template <IndexPageKind kind, typename IndexPage = IndexPageOf<kind>,
typename IndexPageValue = IndexPageValueOf<kind>>
auto InsertIntoPage(IndexPage &page, const KeyType &key, const IndexPageValue &value, const KeyComparator &compare)
-> bool;
}
// cpp file
INDEX_TEMPLATE_ARGUMENTS
template <IndexPageKind kind, typename IndexPage = typename BPLUSTREE_TYPE::template IndexPageOf<kind>, typename IndexPageValue = IndexPageValueOf<kind>>
auto BPLUSTREE_TYPE::InsertIntoPage(IndexPage &page, const KeyType &key, const IndexPageValue &value,
const KeyComparator &compare) -> bool {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment