ocarina/design/index.txt
Anna Schumaker 629cbeb2e9 index: Add a print() function
This function is used in debug mode to print the current status of the
index.  I also created a print_keys() function to only list the keys.

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
2014-04-06 19:56:54 -04:00

81 lines
2.1 KiB
Plaintext

== Files ==
ocarina/include/
index.h
ocarina/lib/
index.cpp
== Depends ==
idle file
Index: (lib/index.cpp)
An inverted index allows me to map multiple values to a single key.
Keys are tracked separately from the rest of the map so they can be
found and iterated over without writing ugly code.
- Index:
class Index {
private:
map<string, set<unsigned int>> index;
set<string> keys;
File file;
public:
Index::Index(filename);
void load();
void save();
void print();
void insert(key, unsigned int);
void remove(key);
void remove(key, unsigned int);
const set<string>::iterator keys_begin();
const set<string>::iterator keys_end();
const set<unsigned int> &operator[](string);
};
File << keys.size() << endl;
File << key << endl;
File << map[key].size() << int_0 << int_1 << ... << int_n << endl;
- API:
Index :: Index(filename);
Initializes an index using ~/.ocarina{-debug}K/filename. Pass
an empty string if you do not want this index to be saved.
void Index :: load();
Reads data from a file. Call after static initialization of
Ocarina to ensure idle tasks are configured
void Index :: save();
Saves data to file
void Index :: print();
This function exists only if CONFIG_DEBUG is enabled.
Following a similar format for writing to disk, print the
index to the console in a human-readable format.
void Index :: print_keys();
This function exists only if CONFIG_DEBUG is enabled.
Print the database keys to the console in a human-readable
format.
void Index :: insert(key, unsigned int);
1) If key does not exist, create it.
2) Add int to the set for the given key
void Index :: remove(key);
Remove a key from the index;
void Index :: remove(key, unsigned int);
1) Remove int from the set of values associated with key
2) If the set is empty, remove the key
const set<string>::iterator void Index :: keys_begin()
Return an iterator pointing to the beginning of the keys set.
const set<string>::iterator void Index :: keys_end()
Return an iterator pointing to the end of the keys set.
const set<unsigned int> &Index :: operator[](string key);
Return the set associated with key