/** * @file * Copyright 2014 (c) Anna Schumaker. */ #include IndexEntry :: IndexEntry() {} IndexEntry :: IndexEntry(const std::string &key) : _key(key) {} const std::string IndexEntry :: primary_key() const { return _key; } void IndexEntry :: insert(unsigned int value) { _values.insert(value); } void IndexEntry :: remove(unsigned int value) { _values.erase(value); } void IndexEntry :: write(File &file) { std::set::iterator it; file << _key << std::endl << _values.size() << " "; for (it = _values.begin(); it != _values.end(); it++) file << *it << " "; } void IndexEntry :: read(File &file) { unsigned int num, val; file >> _key >> num; for (unsigned int i = 0; i < num; i++) { file >> val; insert(val); } } Index :: Index(const std::string &filepath, bool autosave) : Database(filepath, autosave) {} void Index :: insert(const std::string &key, unsigned int val) { IndexEntry *it = find(key); if (it == NULL) it = Database :: insert(IndexEntry(key)); it->insert(val); autosave(); } void Index :: remove(const std::string &key, unsigned int val) { IndexEntry *it = find(key); if (it == NULL) return; it->remove(val); autosave(); }