Initial commit: HTab spreadsheet engine and GemUI X11 frontend
This commit is contained in:
commit
395f458fee
55 files changed
+12682
No files matched your search
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include "engine/address.hpp"
|
||||
#include "engine/parser.hpp"
|
||||
#include "engine/value.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace htab {
|
||||
|
||||
class Workbook;
|
||||
|
||||
class DependencyGraph {
|
||||
public:
|
||||
void clear();
|
||||
void rebuild(Workbook& wb);
|
||||
void update_cell_deps(const Workbook& wb, const GlobalAddr& cell, const Expr* ast);
|
||||
void remove_cell(const GlobalAddr& cell);
|
||||
|
||||
void recalculate_from(Workbook& wb, std::vector<GlobalAddr> seeds);
|
||||
|
||||
bool is_spilled_cell(int sheet, int row, int col) const;
|
||||
std::optional<CellRange> get_spill_range(int sheet, int row, int col) const;
|
||||
std::optional<GlobalAddr> get_spill_origin(int sheet, int row, int col) const;
|
||||
Value get_spill_value(const Workbook& wb, int sheet, int row, int col) const;
|
||||
const std::unordered_map<GlobalAddr, CellRange, GlobalAddrHash>& spill_ranges() const {
|
||||
return spill_ranges_;
|
||||
}
|
||||
|
||||
private:
|
||||
struct LargeRangeEntry {
|
||||
GlobalAddr dependent;
|
||||
CellRange range;
|
||||
};
|
||||
|
||||
void remove_cell_deps_only(const GlobalAddr& cell);
|
||||
void clear_spill_for_origin(const GlobalAddr& origin,
|
||||
std::vector<GlobalAddr>& affected_cells);
|
||||
void clear_blocked_entries_for_origin(const GlobalAddr& origin);
|
||||
bool apply_spill_for_cell(Workbook& wb,
|
||||
const GlobalAddr& origin,
|
||||
const Value& val,
|
||||
std::vector<GlobalAddr>& followup_seeds);
|
||||
void collect_dependents_of(const GlobalAddr& cell,
|
||||
std::vector<GlobalAddr>& out) const;
|
||||
|
||||
std::unordered_map<GlobalAddr, std::vector<GlobalAddr>, GlobalAddrHash> cell_precedents_;
|
||||
std::unordered_map<GlobalAddr, std::vector<CellRange>, GlobalAddrHash> range_precedents_;
|
||||
std::unordered_map<GlobalAddr, std::unordered_set<GlobalAddr, GlobalAddrHash>, GlobalAddrHash>
|
||||
dependents_;
|
||||
std::unordered_map<int, std::vector<LargeRangeEntry>> large_range_dependents_;
|
||||
|
||||
// Spill state
|
||||
std::unordered_map<GlobalAddr, CellRange, GlobalAddrHash> spill_ranges_;
|
||||
std::unordered_map<GlobalAddr, GlobalAddr, GlobalAddrHash> spill_owner_;
|
||||
std::unordered_map<GlobalAddr, std::unordered_set<GlobalAddr, GlobalAddrHash>, GlobalAddrHash>
|
||||
spill_blocked_by_;
|
||||
std::unordered_map<GlobalAddr, std::vector<GlobalAddr>, GlobalAddrHash> origin_blockers_;
|
||||
};
|
||||
|
||||
} // namespace htab
|
||||
Reference in new issue
Block a user