Skip to content

Commit

Permalink
deleting opt type alias and replacing where it was used
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloprobst committed Oct 15, 2024
1 parent 02003d9 commit 41e1c42
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 36 deletions.
12 changes: 6 additions & 6 deletions hyperon_das_atomdb_cpp/src/adapters/ram_only.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ const pair<const int, const AtomList> InMemoryDB::get_atoms_by_index(

//------------------------------------------------------------------------------
const StringList InMemoryDB::get_atoms_by_text_field(const string& text_value,
const opt<string>& field,
const opt<string>& text_index_id) const {
const optional<string>& field,
const optional<string>& text_index_id) const {
throw runtime_error("Not implemented");
}

Expand Down Expand Up @@ -254,7 +254,7 @@ const StringUnorderedSet InMemoryDB::get_matched_type(const string& link_type,
}

//------------------------------------------------------------------------------
const opt<const string> InMemoryDB::get_atom_type(const string& handle) const {
const optional<const string> InMemoryDB::get_atom_type(const string& handle) const {
auto atom = this->_get_atom(handle);
if (atom) {
return atom->named_type;
Expand Down Expand Up @@ -326,7 +326,7 @@ void InMemoryDB::delete_atom(const string& handle) {
const string InMemoryDB::create_field_index(const string& atom_type,
const StringList& fields,
const string& named_type,
const opt<const StringList>& composite_type,
const optional<const StringList>& composite_type,
FieldIndexType index_type) {
throw runtime_error("Not implemented");
}
Expand Down Expand Up @@ -367,7 +367,7 @@ const vector<shared_ptr<const Atom>> InMemoryDB::retrieve_all_atoms() const {
}

//------------------------------------------------------------------------------
void InMemoryDB::commit(const opt<const vector<Atom>>& buffer) {
void InMemoryDB::commit(const optional<const vector<Atom>>& buffer) {
throw runtime_error("Not implemented");
}

Expand Down Expand Up @@ -475,7 +475,7 @@ void InMemoryDB::_add_outgoing_set(const string& key, const StringList& targets_
}

//------------------------------------------------------------------------------
const opt<const StringList> InMemoryDB::_get_and_delete_outgoing_set(const string& handle) {
const optional<const StringList> InMemoryDB::_get_and_delete_outgoing_set(const string& handle) {
auto it = this->db.outgoing_set.find(handle);
if (it != this->db.outgoing_set.end()) {
auto handles = move(it->second);
Expand Down
15 changes: 8 additions & 7 deletions hyperon_das_atomdb_cpp/src/adapters/ram_only.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ class InMemoryDB : public AtomDB {
int cursor = 0,
int chunk_size = 500) const override;

const StringList get_atoms_by_text_field(const string& text_value,
const opt<string>& field = nullopt,
const opt<string>& text_index_id = nullopt) const override;
const StringList get_atoms_by_text_field(
const string& text_value,
const optional<string>& field = nullopt,
const optional<string>& text_index_id = nullopt) const override;

const StringList get_node_by_name_starting_with(const string& node_type,
const string& startswith) const override;
Expand Down Expand Up @@ -152,7 +153,7 @@ class InMemoryDB : public AtomDB {
const StringUnorderedSet get_matched_type(const string& link_type,
const KwArgs& kwargs = {}) const override;

const opt<const string> get_atom_type(const string& handle) const override;
const optional<const string> get_atom_type(const string& handle) const override;

const unordered_map<string, int> count_atoms() const override;

Expand All @@ -170,14 +171,14 @@ class InMemoryDB : public AtomDB {
const string create_field_index(const string& atom_type,
const StringList& fields,
const string& named_type = "",
const opt<const StringList>& composite_type = nullopt,
const optional<const StringList>& composite_type = nullopt,
FieldIndexType index_type = FieldIndexType::BINARY_TREE) override;

void bulk_insert(const vector<shared_ptr<const Atom>>& documents) override;

const vector<shared_ptr<const Atom>> retrieve_all_atoms() const override;

void commit(const opt<const vector<Atom>>& buffer = nullopt) override;
void commit(const optional<const vector<Atom>>& buffer = nullopt) override;

protected:
string database_name;
Expand Down Expand Up @@ -269,7 +270,7 @@ class InMemoryDB : public AtomDB {
* @param handle The handle for which the outgoing set is to be retrieved and deleted.
* @return An optional StringList containing the outgoing set if it exists.
*/
const opt<const StringList> _get_and_delete_outgoing_set(const string& handle);
const optional<const StringList> _get_and_delete_outgoing_set(const string& handle);

/**
* @brief Adds a set of incoming links to the database.
Expand Down
10 changes: 5 additions & 5 deletions hyperon_das_atomdb_cpp/src/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ class AtomDB {
*/
virtual const StringList get_atoms_by_text_field(
const string& text_value,
const opt<string>& field = nullopt,
const opt<string>& text_index_id = nullopt) const = 0;
const optional<string>& field = nullopt,
const optional<string>& text_index_id = nullopt) const = 0;

/**
* @brief Query the database by node name starting with 'startswith' value.
Expand Down Expand Up @@ -316,7 +316,7 @@ class AtomDB {
* @param handle A string representing the handle of the atom.
* @return An optional string containing the type of the atom if found, otherwise nullopt.
*/
virtual const opt<const string> get_atom_type(const string& handle) const = 0;
virtual const optional<const string> get_atom_type(const string& handle) const = 0;

/**
* @brief Count the total number of atoms in the database.
Expand Down Expand Up @@ -421,7 +421,7 @@ class AtomDB {
virtual const string create_field_index(const string& atom_type,
const StringList& fields,
const string& named_type = "",
const opt<const StringList>& composite_type = nullopt,
const optional<const StringList>& composite_type = nullopt,
FieldIndexType index_type = FieldIndexType::BINARY_TREE) = 0;

/**
Expand All @@ -439,7 +439,7 @@ class AtomDB {
/**
* @brief Commit the current state of the database.
*/
virtual void commit(const opt<const vector<Atom>>& buffer = nullopt) = 0;
virtual void commit(const optional<const vector<Atom>>& buffer = nullopt) = 0;

/**
* @brief Reformats a document based on the provided params.
Expand Down
4 changes: 2 additions & 2 deletions hyperon_das_atomdb_cpp/src/document_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ using CustomAttributes = unordered_map<CustomAttributesKey, CustomAttributesValu
* @return An optional value of type T if the custom attribute exists.
*/
template <typename T>
static const opt<T> get_custom_attribute(const CustomAttributes& custom_attributes,
const CustomAttributesKey& key) {
static const optional<T> get_custom_attribute(const CustomAttributes& custom_attributes,
const CustomAttributesKey& key) {
if (custom_attributes.find(key) != custom_attributes.end()) {
return std::get<T>(custom_attributes.at(key));
}
Expand Down
13 changes: 7 additions & 6 deletions hyperon_das_atomdb_cpp/src/nanobind/atom_db_trampoline.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ struct AtomDBTrampoline : AtomDB {
NB_OVERRIDE_PURE(get_atoms_by_index, index_id, query, cursor, chunk_size);
}

const StringList get_atoms_by_text_field(const string& text_value,
const opt<string>& field = nullopt,
const opt<string>& text_index_id = nullopt) const override {
const StringList get_atoms_by_text_field(
const string& text_value,
const optional<string>& field = nullopt,
const optional<string>& text_index_id = nullopt) const override {
NB_OVERRIDE_PURE(get_atoms_by_text_field, text_value, field, text_index_id);
}

Expand Down Expand Up @@ -111,7 +112,7 @@ struct AtomDBTrampoline : AtomDB {
NB_OVERRIDE_PURE(get_matched_type, link_type, kwargs);
}

const opt<const string> get_atom_type(const string& handle) const override {
const optional<const string> get_atom_type(const string& handle) const override {
NB_OVERRIDE_PURE(get_atom_type, handle);
}

Expand All @@ -137,7 +138,7 @@ struct AtomDBTrampoline : AtomDB {
const string create_field_index(const string& atom_type,
const StringList& fields,
const string& named_type = "",
const opt<const StringList>& composite_type = nullopt,
const optional<const StringList>& composite_type = nullopt,
FieldIndexType index_type = FieldIndexType::BINARY_TREE) override {
NB_OVERRIDE_PURE(create_field_index, atom_type, fields, named_type, composite_type, index_type);
}
Expand All @@ -150,7 +151,7 @@ struct AtomDBTrampoline : AtomDB {
NB_OVERRIDE_PURE(retrieve_all_atoms);
}

void commit(const opt<const vector<Atom>>& buffer = nullopt) override {
void commit(const optional<const vector<Atom>>& buffer = nullopt) override {
NB_OVERRIDE_PURE(commit, buffer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ NB_MODULE(ext, m) {
.def("get_atom_type", &AtomDB::get_atom_type, "handle"_a)
.def(
"count_atoms",
[](const AtomDB& self, const opt<const nb::dict>& parameters = nullopt)
[](const AtomDB& self, const optional<const nb::dict>& parameters = nullopt)
-> const unordered_map<string, int> { return self.count_atoms(); },
"parameters"_a = nullopt)
.def("clear_database", &AtomDB::clear_database)
Expand Down
9 changes: 0 additions & 9 deletions hyperon_das_atomdb_cpp/src/type_aliases.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,8 @@ namespace atomdb {

// Type aliases for readability
using uchar = unsigned char;

template <typename T>
using opt = optional<T>;

using StringSet = set<string>;
using StringUnorderedMap = unordered_map<string, string>;
using StringList = vector<string>;
using StringUnorderedSet = unordered_set<string>;
using IntUnorderedMap = unordered_map<string, long>;
using FloatUnorderedMap = unordered_map<string, double>;
using BoolUnorderedMap = unordered_map<string, bool>;

/**
* std::vector<std::any> performs well enough in some particular cases, but be cautious when using it.
Expand Down

0 comments on commit 41e1c42

Please sign in to comment.