Initial commit: HTab spreadsheet engine and GemUI X11 frontend

This commit is contained in:
Luxferre committed 2026-11-30 17:45:17 +02:00
commit 395f458fee
55 files changed
+12682

No files matched your search

+103
View File
@@ -0,0 +1,103 @@
#pragma once
#include <cstddef>
#include <functional>
#include <optional>
#include <string>
#include <string_view>
namespace htab {
inline constexpr int kMaxRows = 1048576;
inline constexpr int kMaxCols = 16384; // A..XFD (0..16383)
struct CellKey {
int row = 0;
int col = 0;
bool operator==(const CellKey&) const = default;
};
struct CellKeyHash {
size_t operator()(const CellKey& k) const noexcept {
size_t h1 = std::hash<int>{}(k.row);
size_t h2 = std::hash<int>{}(k.col);
return h1 ^ (h2 + 0x9e3779b97f4a7c15ULL + (h1 << 6) + (h1 >> 2));
}
};
struct GlobalAddr {
int sheet = 0;
int row = 0;
int col = 0;
bool operator==(const GlobalAddr&) const = default;
};
struct GlobalAddrHash {
size_t operator()(const GlobalAddr& a) const noexcept {
size_t h = std::hash<int>{}(a.sheet);
h ^= std::hash<int>{}(a.row) + 0x9e3779b97f4a7c15ULL + (h << 6) + (h >> 2);
h ^= std::hash<int>{}(a.col) + 0x9e3779b97f4a7c15ULL + (h << 6) + (h >> 2);
return h;
}
};
struct CellRef {
std::string sheet_name;
int row = 0;
int col = 0;
bool abs_row = false;
bool abs_col = false;
bool invalid = false;
bool operator==(const CellRef&) const = default;
};
struct RangeRef {
std::string sheet_name;
CellRef start;
CellRef end;
bool invalid = false;
};
struct CellRange {
int sheet = 0;
int r1 = 0;
int c1 = 0;
int r2 = 0;
int c2 = 0;
bool operator==(const CellRange&) const = default;
int row_count() const { return r2 - r1 + 1; }
int col_count() const { return c2 - c1 + 1; }
bool contains(int s, int r, int c) const {
return s == sheet && r >= r1 && r <= r2 && c >= c1 && c <= c2;
}
};
std::string col_to_letters(int col);
int letters_to_col(std::string_view s);
std::string format_sheet_prefix(const std::string& sheet_name);
std::string format_cell_ref(const CellRef& r);
std::string format_range_ref(const RangeRef& r);
std::optional<CellRef> parse_cell_ref(std::string_view text);
enum class StructuralOp {
InsertRow,
DeleteRow,
InsertCol,
DeleteCol,
RenameSheet,
DeleteSheet,
};
std::string translate_formula_refs(const std::string& formula, int drow, int dcol);
std::string rewrite_formula_structural(const std::string& formula,
const std::string& current_sheet,
const std::string& target_sheet,
StructuralOp op,
int index,
int count,
const std::string& new_name = "");
} // namespace htab