[dasher] Cleanup Alphabet(Map) e.g. g/c KeyIsPrefix.
- From: Patrick Welche <pwelche src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [dasher] Cleanup Alphabet(Map) e.g. g/c KeyIsPrefix.
- Date: Sat, 15 Aug 2009 14:22:58 +0000 (UTC)
commit 831c8707da98218925819f05628795d2e4bbcf8c
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Mon Aug 10 09:45:24 2009 +0200
Cleanup Alphabet(Map) e.g. g/c KeyIsPrefix.
ChangeLog | 1 +
Src/DasherCore/Alphabet/Alphabet.cpp | 44 ++++--------------------------
Src/DasherCore/Alphabet/Alphabet.h | 4 ---
Src/DasherCore/Alphabet/AlphabetMap.cpp | 25 +++--------------
Src/DasherCore/Alphabet/AlphabetMap.h | 10 ++-----
5 files changed, 14 insertions(+), 70 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e6586a0..8e0e151 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
2009-08-10 Alan Lawrence <acl33 inf phy cam ac uk>
* Remove unused GetRenderCount methods
+ * Cleanup Alphabet(Map) e.g. g/c KeyIsPrefix.
2009-08-08 Alan Lawrence <acl33 inf phy cam ac uk>
diff --git a/Src/DasherCore/Alphabet/Alphabet.cpp b/Src/DasherCore/Alphabet/Alphabet.cpp
index 40deb9a..ddf1472 100644
--- a/Src/DasherCore/Alphabet/Alphabet.cpp
+++ b/Src/DasherCore/Alphabet/Alphabet.cpp
@@ -152,7 +152,6 @@ int CAlphabet::utf8_length::operator[](const int i) const
void CAlphabet::GetSymbols(std::vector<symbol> &symbols, std::istream &in) const
{
- bool unused;
char skip, *utfchar = new char[m_utf8_count_array.max_length + 1];
symbol sym;
int len, ch = in.peek();
@@ -171,7 +170,7 @@ void CAlphabet::GetSymbols(std::vector<symbol> &symbols, std::istream &in) const
{
in.read(utfchar, len);
utfchar[len] = '\0';
- sym = TextMap.Get(string(utfchar), &unused);
+ sym = TextMap.Get(string(utfchar));
symbols.push_back(sym);
}
ch = in.peek();
@@ -183,7 +182,6 @@ void CAlphabet::GetSymbols(std::vector<symbol> *Symbols, std::string * Input, bo
{
string Tmp;
symbol CurSymbol = 0, TmpSymbol = 0;
- bool KeyIsPrefix = false;
int extras;
unsigned int bit;
@@ -207,44 +205,14 @@ void CAlphabet::GetSymbols(std::vector<symbol> *Symbols, std::string * Input, bo
}
}
- CurSymbol = TextMap.Get(Tmp, &KeyIsPrefix);
+ CurSymbol = TextMap.Get(Tmp);
- if(KeyIsPrefix) {
- CurSymbol = 0;
- for(; i < Input->size(); i++) {
-
- Tmp += (*Input)[i];
-
- TmpSymbol = TextMap.Get(Tmp, &KeyIsPrefix);
- if(TmpSymbol > 0) {
- CurSymbol = TmpSymbol;
- }
- if(!KeyIsPrefix) {
- if(CurSymbol != 0) {
- Symbols->push_back(CurSymbol);
- }
- else {
- i -= Tmp.size() - 1;
- //Tmp.erase(Tmp.begin(), Tmp.end());
- Tmp = "";
- }
- break;
- }
- }
- }
- else {
- if(CurSymbol != 0)
- Symbols->push_back(CurSymbol);
- }
+ if(CurSymbol != 0)
+ Symbols->push_back(CurSymbol);
}
if(IsMore)
- if(KeyIsPrefix)
- *Input = Tmp;
- else
- *Input = "";
- else if(KeyIsPrefix)
- Symbols->push_back(CurSymbol);
+ *Input = "";
}
void CAlphabet::GetSymbolsFull(std::vector<symbol > *Symbols, std::string *Input) const {
@@ -278,7 +246,7 @@ void CAlphabet::GetSymbolsFull(std::vector<symbol > *Symbols, std::string *Input
// TODO: Error condition on reaching end of string prematurely.
- Symbols->push_back(TextMap.Get(strCurrentSymbol, NULL));
+ Symbols->push_back(TextMap.Get(strCurrentSymbol));
++it;
}
diff --git a/Src/DasherCore/Alphabet/Alphabet.h b/Src/DasherCore/Alphabet/Alphabet.h
index 32942a6..e14396f 100644
--- a/Src/DasherCore/Alphabet/Alphabet.h
+++ b/Src/DasherCore/Alphabet/Alphabet.h
@@ -151,10 +151,6 @@ namespace Dasher {
m_DefaultPalette = Palette;
}
- const alphabet_map GetAlphabetMap() const {
- return TextMap;
- }
-
const std::string &GetDefaultContext() const {
return m_strDefaultContext;
}
diff --git a/Src/DasherCore/Alphabet/AlphabetMap.cpp b/Src/DasherCore/Alphabet/AlphabetMap.cpp
index 65c0ee0..c4299fd 100644
--- a/Src/DasherCore/Alphabet/AlphabetMap.cpp
+++ b/Src/DasherCore/Alphabet/AlphabetMap.cpp
@@ -30,26 +30,13 @@ alphabet_map::alphabet_map(unsigned int InitialTableSize)
}
void alphabet_map::Add(const std::string &Key, symbol Value) {
- RecursiveAdd(Key, Value, false);
-}
-
-void alphabet_map::RecursiveAdd(const std::string &Key, symbol Value, bool PrefixFlag) {
Entry *&HashEntry = HashTable[Hash(Key)];
// Loop through Entries with the correct Hash value.
for(Entry * i = HashEntry; i; i = i->Next) {
if(i->Key == Key) {
- if(PrefixFlag) {
- // Just tagging - don't change symbol. Recurse if necessary
- i->KeyIsPrefix = true;
- if(Key.size() > 1)
- RecursiveAdd(Key.substr(Key.size() - 1), Undefined, true);
- }
- else {
- // Add symbol and leave
- i->Symbol = Value;
- }
- return;
+ // Add symbol and leave
+ i->Symbol = Value;
}
}
@@ -69,7 +56,7 @@ void alphabet_map::RecursiveAdd(const std::string &Key, symbol Value, bool Prefi
}
// Have to recall this function as the key's hash needs recalculating
- RecursiveAdd(Key, Value, PrefixFlag);
+ Add(Key, Value);
return;
}
@@ -77,18 +64,14 @@ void alphabet_map::RecursiveAdd(const std::string &Key, symbol Value, bool Prefi
HashEntry = &Entries.back();
}
-symbol alphabet_map::Get(const std::string &Key, bool *KeyIsPrefix) const {
+symbol alphabet_map::Get(const std::string &Key) const {
// Loop through Entries with the correct Hash value.
for(Entry * i = HashTable[Hash(Key)]; i; i = i->Next) {
if(i->Key == Key) {
- if(KeyIsPrefix != 0)
- *KeyIsPrefix = i->KeyIsPrefix;
return i->Symbol;
}
}
- if(KeyIsPrefix != 0)
- *KeyIsPrefix = false;
return Undefined;
}
diff --git a/Src/DasherCore/Alphabet/AlphabetMap.h b/Src/DasherCore/Alphabet/AlphabetMap.h
index d6e521c..c0b7d02 100644
--- a/Src/DasherCore/Alphabet/AlphabetMap.h
+++ b/Src/DasherCore/Alphabet/AlphabetMap.h
@@ -67,23 +67,19 @@ public:
alphabet_map(unsigned int InitialTableSize = 255);
void Add(const std::string & Key, symbol Value);
- // Return the symbol associated with Key or Undefined. KeyIsPrefix, if non
- // NULL, will be set to true if ???
- symbol Get(const std::string & Key, bool * KeyIsPrefix) const;
+ // Return the symbol associated with Key or Undefined.
+ symbol Get(const std::string & Key) const;
private:
class Entry {
public:
Entry(std::string Key, symbol Symbol, Entry * Next)
- : Key(Key), KeyIsPrefix(false), Symbol(Symbol), Next(Next) {
+ : Key(Key), Symbol(Symbol), Next(Next) {
} std::string Key;
- bool KeyIsPrefix;
symbol Symbol;
Entry *Next;
};
- void RecursiveAdd(const std::string & Key, symbol Value, bool PrefixFlag);
-
// A standard hash -- could try and research something specific.
inline unsigned int Hash(const std::string & Input) const {
unsigned int Result = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]