Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ struct SchemaRef {
std::string schema_;
std::string value_;
bool declaration_;
// Cached 16-bit tag for fast path operations (e.g., BFS packing)
uint16_t schema_tag_ = 0;

public:
[[nodiscard]] std::string schema() const { return schema_; }
[[nodiscard]] std::string value() const { return value_; }
[[nodiscard]] bool is_declaration() const { return declaration_; }
[[nodiscard]] uint16_t tag() const { return schema_tag_; }
void set_tag(uint16_t t) { schema_tag_ = t; }

static SchemaRef parse(const std::string& s) {
SchemaRef r;
Expand Down Expand Up @@ -154,6 +158,10 @@ class Traverse final : public Clause {
[[nodiscard]] const std::string& edge_type() const { return edge_type_; }
[[nodiscard]] const SchemaRef& target() const { return target_; }
[[nodiscard]] TraverseType traverse_type() const { return traverse_type_; }

// Internal mutation helpers for precomputing tags
SchemaRef& mutable_source() { return source_; }
SchemaRef& mutable_target() { return target_; }
};

struct Select final : Clause {
Expand Down
23 changes: 12 additions & 11 deletions include/schema_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@ namespace tundradb {
* Helper functions for bit set manipulation to track which fields are set
*/
inline size_t get_bitset_size_bytes(const size_t num_fields) {
return (num_fields + 7) / 8; // Round up to nearest byte
size_t bit_words = (num_fields + 63) / 64;
size_t bitset_bytes = bit_words * sizeof(uint64_t);
return bitset_bytes;
}

inline bool is_field_set(const char* bitset, const size_t field_index) {
const size_t byte_index = field_index / 8;
const size_t bit_index = field_index % 8;
return (bitset[byte_index] & (1 << bit_index)) != 0;
inline bool is_field_set(const char* base, const size_t idx) {
auto words = reinterpret_cast<const uint64_t*>(base);
return (words[idx >> 6] >> (idx & 63)) & 1ULL;
}

inline void set_field_bit(char* bitset, const size_t field_index,
const bool is_set) {
const size_t byte_index = field_index / 8;
const size_t bit_index = field_index % 8;
inline void set_field_bit(char* base, size_t idx, bool is_set) {
auto words = reinterpret_cast<uint64_t*>(base);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better than byte per field

uint64_t mask = 1ULL << (idx & 63);
uint64_t& w = words[idx >> 6];
if (is_set) {
bitset[byte_index] |= (1 << bit_index);
w |= mask;
} else {
bitset[byte_index] &= ~(1 << bit_index);
w &= ~mask;
}
}

Expand Down
6 changes: 4 additions & 2 deletions include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <arrow/datum.h>
#include <arrow/result.h>
#include <arrow/table.h>
#include <llvm/ADT/DenseSet.h>
#include <uuid/uuid.h>

#include <iostream>
Expand Down Expand Up @@ -84,7 +85,7 @@ static arrow::Result<std::shared_ptr<arrow::Table>> filter_table_by_id(
return filtered_table.table();
}

static arrow::Result<std::set<int64_t>> get_ids_from_table(
static arrow::Result<llvm::DenseSet<int64_t>> get_ids_from_table(
std::shared_ptr<arrow::Table> table) {
log_debug("Extracting IDs from table with {} rows", table->num_rows());

Expand All @@ -95,7 +96,8 @@ static arrow::Result<std::set<int64_t>> get_ids_from_table(
}

auto id_column = table->column(id_idx);
std::set<int64_t> result_ids;
llvm::DenseSet<int64_t> result_ids;
result_ids.reserve(table->num_rows());

for (int chunk_idx = 0; chunk_idx < id_column->num_chunks(); chunk_idx++) {
auto chunk = std::static_pointer_cast<arrow::Int64Array>(
Expand Down
Loading