/** * @file * Copyright 2014 (c) Anna Schumaker. */ #ifndef OCARINA_CORE_INDEX_H #define OCARINA_CORE_INDEX_H #include #include #include /** * The IndexEntry class is used to associate a specific key with a set of * integer identifiers. This lets us use a Database as an inverted index. */ class IndexEntry : public DatabaseEntry { public: std::string _key; /**< The term stored by this IndexEntry. */ std::set _values; /**< Integers representing strings that contain this term. */ IndexEntry(); /**< Create an empty IndexEntry. */ /** * Create an IndexEntry with a specific key. * * @param key The key associated with this IndexEntry. */ IndexEntry(const std::string &); /** * Access the key stored by this IndexEntry. * * @return IndexEntry::_key. */ const std::string primary_key() const; /** * Add a new value to this IndexEntry. * * @param value The new value to add. */ void insert(unsigned int); /** * Remove a value from this IndexEntry. * * @param value The value to remove. */ void remove(unsigned int); /** * Write an IndexEntry to file. * * @param file The file to use when writing data. */ void write(File &); /** * Read an IndexEntry from file. * * @param file The file read from. */ void read(File &); }; /** * A special Database for index access. */ class Index : public Database { public: /** * Index constructor. * @param filepath Where to store the file on disk. * @param autosave True if changes should automatically be saved. */ Index(const std::string &, bool); /** * Add a new (key, value) pair to the index. * @param key String to store in the index. * @param value Integer value associated with the key. */ void insert(const std::string &, unsigned int); /** * Remove a (key, value) pair from the index. * @param key Key associated with the value to be removed. * @param value Value to remove from the index. */ void remove(const std::string &, unsigned int); }; #endif /* OCARINA_CORE_DATABASE_H */