src: remove unused stuff
* PersistenStorage::removeUnusedNames * Dictionary * DictionaryTestSuite
This commit is contained in:
@@ -299,8 +299,6 @@ add_files(
|
||||
utility/solution/SolutionParserVisualStudio.cpp
|
||||
utility/solution/SolutionParserVisualStudio.h
|
||||
|
||||
utility/text/Dictionary.cpp
|
||||
utility/text/Dictionary.h
|
||||
utility/text/TextAccess.cpp
|
||||
utility/text/TextAccess.h
|
||||
|
||||
|
||||
@@ -304,13 +304,6 @@ void PersistentStorage::clearFileElements(const std::vector<FilePath>& filePaths
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::removeUnusedNames() // maybe rename this function. look for callers first.
|
||||
{
|
||||
// m_sqliteStorage.removeUnusedNameHierarchyElements();
|
||||
|
||||
clearCaches();
|
||||
}
|
||||
|
||||
std::vector<FileInfo> PersistentStorage::getInfoOnAllFiles() const
|
||||
{
|
||||
std::vector<FileInfo> fileInfos;
|
||||
|
||||
@@ -61,7 +61,6 @@ public:
|
||||
std::set<FilePath> getDependingFilePaths(const FilePath& filePath);
|
||||
|
||||
void clearFileElements(const std::vector<FilePath>& filePaths);
|
||||
void removeUnusedNames();
|
||||
|
||||
std::vector<FileInfo> getInfoOnAllFiles() const;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ Task::TaskState TaskCleanStorage::update()
|
||||
if (m_fileCount)
|
||||
{
|
||||
MessageStatus("Cleaning up names (ESC to quit)", false, true).dispatch();
|
||||
m_storage->removeUnusedNames();
|
||||
m_storage->clearCaches();
|
||||
}
|
||||
|
||||
return Task::STATE_FINISHED;
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
#include "utility/text/Dictionary.h"
|
||||
|
||||
#include "data/name/NameHierarchy.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
Dictionary::Dictionary()
|
||||
{
|
||||
}
|
||||
|
||||
Dictionary::~Dictionary()
|
||||
{
|
||||
}
|
||||
|
||||
void Dictionary::clear()
|
||||
{
|
||||
m_words.clear();
|
||||
m_ids.clear();
|
||||
}
|
||||
|
||||
size_t Dictionary::getCharCount() const
|
||||
{
|
||||
size_t count = 0;
|
||||
|
||||
for (const std::pair<Id, std::string>& p : m_words)
|
||||
{
|
||||
count += p.second.size();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t Dictionary::getWordCount() const
|
||||
{
|
||||
return m_words.size();
|
||||
}
|
||||
|
||||
Id Dictionary::getWordId(const std::string& word)
|
||||
{
|
||||
Id wordId = getWordIdConst(word);
|
||||
if (wordId)
|
||||
{
|
||||
return wordId;
|
||||
}
|
||||
|
||||
m_words.emplace(++s_nextId, word);
|
||||
m_ids.emplace(word, s_nextId);
|
||||
return s_nextId;
|
||||
}
|
||||
|
||||
Id Dictionary::getWordIdConst(const std::string& word) const
|
||||
{
|
||||
std::unordered_map<std::string, Id>::const_iterator it = m_ids.find(word);
|
||||
|
||||
if (it != m_ids.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::deque<Id> Dictionary::getWordIds(const std::string& wordList, const std::string& delimiter)
|
||||
{
|
||||
std::deque<std::string> words = utility::split(wordList, delimiter);
|
||||
std::deque<Id> ids;
|
||||
|
||||
for (const std::string& word: words)
|
||||
{
|
||||
ids.push_back(getWordId(word));
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
std::deque<Id> Dictionary::getWordIdsConst(const std::string& wordList, const std::string& delimiter) const
|
||||
{
|
||||
std::deque<std::string> words = utility::split(wordList, delimiter);
|
||||
std::deque<Id> ids;
|
||||
|
||||
for (const std::string& word: words)
|
||||
{
|
||||
ids.push_back(getWordIdConst(word));
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
std::deque<Id> Dictionary::getWordIdsConst(const NameHierarchy& nameHierarchy) const
|
||||
{
|
||||
std::deque<Id> ids;
|
||||
|
||||
for (size_t i = 0; i < nameHierarchy.size(); i++)
|
||||
{
|
||||
ids.push_back(getWordIdConst(nameHierarchy[i]->getName()));
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
const std::string& Dictionary::getWord(Id id) const
|
||||
{
|
||||
std::unordered_map<Id, std::string>::const_iterator it = m_words.find(id);
|
||||
|
||||
if (it != m_words.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return m_emptyWord;
|
||||
}
|
||||
|
||||
std::string Dictionary::getWord(const std::deque<Id> ids, const std::string& delimiter) const
|
||||
{
|
||||
std::string word;
|
||||
|
||||
for (std::deque<Id>::const_iterator it = ids.begin(); it != ids.end(); it++)
|
||||
{
|
||||
if (it != ids.begin())
|
||||
{
|
||||
word += delimiter;
|
||||
}
|
||||
|
||||
word += getWord(*it);
|
||||
}
|
||||
|
||||
return word;
|
||||
}
|
||||
|
||||
Id Dictionary::s_nextId = 0;
|
||||
@@ -1,44 +0,0 @@
|
||||
#ifndef DICTIONARY_H
|
||||
#define DICTIONARY_H
|
||||
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
class NameHierarchy;
|
||||
|
||||
class Dictionary
|
||||
{
|
||||
public:
|
||||
Dictionary();
|
||||
~Dictionary();
|
||||
|
||||
void clear();
|
||||
|
||||
size_t getCharCount() const;
|
||||
size_t getWordCount() const;
|
||||
|
||||
Id getWordId(const std::string& word);
|
||||
Id getWordIdConst(const std::string& word) const;
|
||||
|
||||
std::deque<Id> getWordIds(const std::string& wordList, const std::string& delimiter);
|
||||
std::deque<Id> getWordIdsConst(const std::string& wordList, const std::string& delimiter) const;
|
||||
std::deque<Id> getWordIdsConst(const NameHierarchy& nameHierarchy) const;
|
||||
|
||||
// Note: References to values in an unordered_map don't change on rehashing so they can be saved and used elsewhere.
|
||||
const std::string& getWord(Id id) const;
|
||||
std::string getWord(const std::deque<Id> ids, const std::string& delimiter) const;
|
||||
|
||||
private:
|
||||
static Id s_nextId;
|
||||
|
||||
std::unordered_map<Id, std::string> m_words;
|
||||
std::unordered_map<std::string, Id> m_ids; // TODO: replace id lookup to consume less momory e.g. Search Trie
|
||||
std::string m_emptyWord;
|
||||
};
|
||||
|
||||
#endif // DICTIONARY_H
|
||||
@@ -10,7 +10,6 @@ add_files(
|
||||
ConfigManagerTestSuite.h
|
||||
CxxParserTestSuite.h
|
||||
DataTypeTestSuite.h
|
||||
DictionaryTestSuite.h
|
||||
FileManagerTestSuite.h
|
||||
FilePathTestSuite.h
|
||||
FileSystemTestSuite.h
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
#include "cxxtest/TestSuite.h"
|
||||
|
||||
#include "utility/text/Dictionary.h"
|
||||
|
||||
class DictionaryTestSuite: public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_does_not_find_unsaved_word()
|
||||
{
|
||||
Dictionary dictionary;
|
||||
TS_ASSERT_EQUALS("", dictionary.getWord(12));
|
||||
}
|
||||
|
||||
void test_can_save_word_and_retrieve_it_with_id()
|
||||
{
|
||||
Dictionary dictionary;
|
||||
Id id = dictionary.getWordId("hello world!");
|
||||
|
||||
TS_ASSERT_LESS_THAN(0, id);
|
||||
TS_ASSERT_EQUALS("hello world!", dictionary.getWord(id));
|
||||
}
|
||||
|
||||
void test_can_save_multiple_words_and_retrieve_it_with_id()
|
||||
{
|
||||
Dictionary dictionary;
|
||||
std::deque<Id> ids = dictionary.getWordIds("hello world!", " ");
|
||||
|
||||
TS_ASSERT_EQUALS(2, ids.size());
|
||||
TS_ASSERT_EQUALS("hello", dictionary.getWord(ids.front()));
|
||||
TS_ASSERT_EQUALS("world!", dictionary.getWord(ids.back()));
|
||||
TS_ASSERT_EQUALS("hello world!", dictionary.getWord(ids, " "));
|
||||
}
|
||||
|
||||
void test_next_word_gets_different_id()
|
||||
{
|
||||
Dictionary dictionary;
|
||||
Id id = dictionary.getWordId("hello world!");
|
||||
Id id2 = dictionary.getWordId("foobar");
|
||||
|
||||
TS_ASSERT_LESS_THAN(0, id);
|
||||
TS_ASSERT_LESS_THAN(0, id2);
|
||||
TS_ASSERT_LESS_THAN(id, id2);
|
||||
|
||||
TS_ASSERT_EQUALS("hello world!", dictionary.getWord(id));
|
||||
TS_ASSERT_EQUALS("foobar", dictionary.getWord(id2));
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user