A lot of changes. Probably works now.
In procCross now argument isn't a array of wxChars, but array of 1-byte numbers. It should improve performance.
This commit is contained in:
@@ -13,7 +13,7 @@ CurrentFileName :=
|
|||||||
CurrentFilePath :=
|
CurrentFilePath :=
|
||||||
CurrentFileFullPath :=
|
CurrentFileFullPath :=
|
||||||
User :=Aleksey Lobanov
|
User :=Aleksey Lobanov
|
||||||
Date :=13/06/15
|
Date :=14/06/15
|
||||||
CodeLitePath :="/home/alex/.codelite"
|
CodeLitePath :="/home/alex/.codelite"
|
||||||
LinkerName :=/usr/bin/g++-4.8
|
LinkerName :=/usr/bin/g++-4.8
|
||||||
SharedObjectLinkerName :=/usr/bin/g++-4.8 -shared -fPIC
|
SharedObjectLinkerName :=/usr/bin/g++-4.8 -shared -fPIC
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
<Project Name="wxCrossGen" Path="wxCrossGen/wxCrossGen.project" Active="Yes"/>
|
<Project Name="wxCrossGen" Path="wxCrossGen/wxCrossGen.project" Active="Yes"/>
|
||||||
<Project Name="CrossBench" Path="CrossBench/CrossBench.project" Active="No"/>
|
<Project Name="CrossBench" Path="CrossBench/CrossBench.project" Active="No"/>
|
||||||
<BuildMatrix>
|
<BuildMatrix>
|
||||||
<WorkspaceConfiguration Name="Debug" Selected="yes">
|
<WorkspaceConfiguration Name="Debug" Selected="no">
|
||||||
<Project Name="wxCrossGen" ConfigName="Debug"/>
|
<Project Name="wxCrossGen" ConfigName="Debug"/>
|
||||||
<Project Name="CrossBench" ConfigName="Debug"/>
|
<Project Name="CrossBench" ConfigName="Debug"/>
|
||||||
</WorkspaceConfiguration>
|
</WorkspaceConfiguration>
|
||||||
<WorkspaceConfiguration Name="Release" Selected="no">
|
<WorkspaceConfiguration Name="Release" Selected="yes">
|
||||||
<Project Name="wxCrossGen" ConfigName="Release"/>
|
<Project Name="wxCrossGen" ConfigName="Release"/>
|
||||||
<Project Name="CrossBench" ConfigName="Release"/>
|
<Project Name="CrossBench" ConfigName="Release"/>
|
||||||
</WorkspaceConfiguration>
|
</WorkspaceConfiguration>
|
||||||
|
|||||||
8
Makefile
8
Makefile
@@ -1,8 +1,8 @@
|
|||||||
.PHONY: clean All
|
.PHONY: clean All
|
||||||
|
|
||||||
All:
|
All:
|
||||||
@echo "----------Building project:[ wxCrossGen - Debug ]----------"
|
@echo "----------Building project:[ CrossBench - Release ]----------"
|
||||||
@cd "wxCrossGen" && $(MAKE) -f "wxCrossGen.mk"
|
@cd "CrossBench" && $(MAKE) -f "CrossBench.mk"
|
||||||
clean:
|
clean:
|
||||||
@echo "----------Cleaning project:[ wxCrossGen - Debug ]----------"
|
@echo "----------Cleaning project:[ CrossBench - Release ]----------"
|
||||||
@cd "wxCrossGen" && $(MAKE) -f "wxCrossGen.mk" clean
|
@cd "CrossBench" && $(MAKE) -f "CrossBench.mk" clean
|
||||||
|
|||||||
@@ -8,9 +8,15 @@
|
|||||||
|
|
||||||
typedef std::map< wxString, wxString > DictType;
|
typedef std::map< wxString, wxString > DictType;
|
||||||
typedef std::vector< std::vector< wxChar > > GridType;
|
typedef std::vector< std::vector< wxChar > > GridType;
|
||||||
typedef std::vector< std::vector<wxChar> > CurGridType;
|
|
||||||
|
typedef uint8_t TransedChar;
|
||||||
|
typedef std::vector< TransedChar > TransedWord;
|
||||||
|
|
||||||
|
typedef std::vector< std::vector< TransedChar > > WorkGridType;
|
||||||
|
typedef std::map< wxChar, TransedChar > CharsTransType;
|
||||||
|
typedef std::map< TransedChar, wxChar > BackedCharsTransType;
|
||||||
// Fisrt index is a word length
|
// Fisrt index is a word length
|
||||||
typedef std::vector< std::vector<wxString> > AllWordsType;
|
typedef std::vector< std::vector< TransedWord > > AllWordsType;
|
||||||
typedef std::set< uint32_t > UsedWords;
|
typedef std::set< uint32_t > UsedWords;
|
||||||
|
|
||||||
struct WordInfo {
|
struct WordInfo {
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
#include "crossbasetypes.hpp"
|
#include "crossbasetypes.hpp"
|
||||||
|
|
||||||
const wxChar CELL_CLEAR = wxT('+');
|
const wxChar CELL_CLEAR = wxT('+');
|
||||||
|
const wxChar CELL_BORDER = wxT('-');
|
||||||
|
const TransedChar TRANS_CLEAR = 0;
|
||||||
|
const TransedChar TRANS_BORDER = 1;
|
||||||
const uint32_t MAX_WORD_COUNT = 262144; // =2^18
|
const uint32_t MAX_WORD_COUNT = 262144; // =2^18
|
||||||
|
|
||||||
void readDict(const wxString path, DictType &dict){
|
void readDict(const wxString path, DictType &dict){
|
||||||
@@ -49,12 +52,57 @@ void readGrid(const wxString path, GridType &grid){
|
|||||||
f.Close();
|
f.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateAllWords(const DictType &dict, AllWordsType &words_out){
|
wxString getFromTransed(const TransedWord &tw, const BackedCharsTransType &bchar_trans){
|
||||||
|
wxString s;
|
||||||
|
s.resize(tw.size());
|
||||||
|
for (size_t i = 0; i < tw.size(); ++i){
|
||||||
|
s[i] = bchar_trans.at(tw.at(i));
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
BackedCharsTransType getFromCharsTransed(const CharsTransType &char_trans){
|
||||||
|
BackedCharsTransType t;
|
||||||
|
for (auto it = char_trans.begin(); it != char_trans.end(); ++it)
|
||||||
|
t[it->second] = it->first;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
void toWorkGridType(const GridType &grid, WorkGridType &grid_out){
|
||||||
|
grid_out.clear();
|
||||||
|
grid_out.resize(grid.size());
|
||||||
|
for (size_t i = 0; i < grid.size(); ++i){
|
||||||
|
grid_out.at(i).resize(grid.at(0).size());
|
||||||
|
for (size_t j = 0; j < grid.at(0).size(); ++j){
|
||||||
|
if ( grid.at(i).at(j) == CELL_CLEAR )
|
||||||
|
grid_out.at(i).at(j) = TRANS_CLEAR;
|
||||||
|
else
|
||||||
|
grid_out.at(i).at(j) = TRANS_BORDER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateAllWords(const DictType &dict, AllWordsType &words_out,
|
||||||
|
CharsTransType &char_trans_out){
|
||||||
words_out.clear();
|
words_out.clear();
|
||||||
|
char_trans_out.clear();
|
||||||
|
char_trans_out[CELL_CLEAR] = TRANS_CLEAR;
|
||||||
|
char_trans_out[CELL_BORDER] = TRANS_BORDER;
|
||||||
|
static_assert(TRANS_CLEAR + 1 == TRANS_BORDER, "TRANS_CLEAR + 1 != TRANS_BORDER");
|
||||||
|
TransedChar st = TRANS_BORDER + 1;
|
||||||
for (auto it = dict.begin(); it != dict.end(); ++it){
|
for (auto it = dict.begin(); it != dict.end(); ++it){
|
||||||
if ( words_out.size() <= it->first.size() )
|
if ( words_out.size() <= it->first.size() )
|
||||||
words_out.resize(it->first.size() + 2);
|
words_out.resize(it->first.size() + 2);
|
||||||
words_out.at(it->first.size()).push_back(it->first);
|
TransedWord t_tw(it->first.size());
|
||||||
|
for (size_t i = 0; i < it->first.size(); ++i){
|
||||||
|
auto cur_ch = it->first.at(i);
|
||||||
|
if ( char_trans_out.find(cur_ch) == char_trans_out.end() ){
|
||||||
|
char_trans_out[cur_ch] = st;
|
||||||
|
++st;
|
||||||
|
}
|
||||||
|
t_tw.at(i) = char_trans_out[cur_ch];
|
||||||
|
}
|
||||||
|
words_out.at(it->first.size()).push_back(t_tw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,8 +179,8 @@ uint32_t getWordUniq(const T &w_ind, const T &w_len){
|
|||||||
return w_ind + w_len * MAX_WORD_COUNT;
|
return w_ind + w_len * MAX_WORD_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool procCross(UsedWords used, AllWordsType &words, CurGridType grid,
|
bool procCross(UsedWords used, AllWordsType &words, WorkGridType grid,
|
||||||
std::vector<WordInfo> &winfos, size_t cur_word_ind, std::vector<wxString> &out){
|
std::vector<WordInfo> &winfos, size_t cur_word_ind, std::vector<TransedWord> &out){
|
||||||
if (cur_word_ind == winfos.size())
|
if (cur_word_ind == winfos.size())
|
||||||
return true;
|
return true;
|
||||||
WordInfo cur_wi = winfos.at(cur_word_ind);
|
WordInfo cur_wi = winfos.at(cur_word_ind);
|
||||||
@@ -142,19 +190,19 @@ bool procCross(UsedWords used, AllWordsType &words, CurGridType grid,
|
|||||||
for (size_t icw = 0; icw < cur_words_size; ++icw){
|
for (size_t icw = 0; icw < cur_words_size; ++icw){
|
||||||
if (used.find(getWordUniq(icw,cur_len)) != used.end())
|
if (used.find(getWordUniq(icw,cur_len)) != used.end())
|
||||||
continue;
|
continue;
|
||||||
wxString cur_word = words.at(cur_len).at((icw + rand_add) % cur_words_size);
|
TransedWord cur_word = words.at(cur_len).at((icw + rand_add) % cur_words_size);
|
||||||
// Показывает, можно ли записать это слово в сетку
|
// Показывает, можно ли записать это слово в сетку
|
||||||
bool can_write = true;
|
bool can_write = true;
|
||||||
if (cur_wi.direct == false){
|
if (cur_wi.direct == false){
|
||||||
for (size_t j = 0; j < cur_wi.len; ++j)
|
for (size_t j = 0; j < cur_wi.len; ++j)
|
||||||
if ((grid.at(cur_wi.x).at(j + cur_wi.y) != CELL_CLEAR) &&
|
if ((grid.at(cur_wi.x).at(j + cur_wi.y) != TRANS_CLEAR) &&
|
||||||
(grid.at(cur_wi.x).at(j + cur_wi.y) != cur_word.at(j)))
|
(grid.at(cur_wi.x).at(j + cur_wi.y) != cur_word.at(j)))
|
||||||
can_write = false;
|
can_write = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cur_wi.direct == true){
|
if (cur_wi.direct == true){
|
||||||
for (size_t j = 0; j < cur_wi.len; ++j)
|
for (size_t j = 0; j < cur_wi.len; ++j)
|
||||||
if ((grid.at(cur_wi.x + j).at(cur_wi.y) != CELL_CLEAR) &&
|
if ((grid.at(cur_wi.x + j).at(cur_wi.y) != TRANS_CLEAR) &&
|
||||||
(grid.at(cur_wi.x + j).at(cur_wi.y) != cur_word.at(j)))
|
(grid.at(cur_wi.x + j).at(cur_wi.y) != cur_word.at(j)))
|
||||||
can_write = false;
|
can_write = false;
|
||||||
}
|
}
|
||||||
@@ -163,7 +211,7 @@ bool procCross(UsedWords used, AllWordsType &words, CurGridType grid,
|
|||||||
UsedWords t_used(used);
|
UsedWords t_used(used);
|
||||||
t_used.insert(getWordUniq(icw,cur_len));
|
t_used.insert(getWordUniq(icw,cur_len));
|
||||||
|
|
||||||
CurGridType t_grid(grid);
|
WorkGridType t_grid(grid);
|
||||||
|
|
||||||
if ( cur_wi.direct ){
|
if ( cur_wi.direct ){
|
||||||
for (size_t j = 0; j < cur_wi.len; ++j)
|
for (size_t j = 0; j < cur_wi.len; ++j)
|
||||||
@@ -184,15 +232,25 @@ bool procCross(UsedWords used, AllWordsType &words, CurGridType grid,
|
|||||||
|
|
||||||
void generateCross(GridType &grid, const DictType &dict, std::vector<wxString> &words_out){
|
void generateCross(GridType &grid, const DictType &dict, std::vector<wxString> &words_out){
|
||||||
AllWordsType words;
|
AllWordsType words;
|
||||||
generateAllWords(dict, words);
|
CharsTransType trans_type;
|
||||||
|
generateAllWords(dict, words, trans_type);
|
||||||
std::vector<WordInfo> winfos;
|
std::vector<WordInfo> winfos;
|
||||||
generateWordInfo(grid, winfos);
|
generateWordInfo(grid, winfos);
|
||||||
for (size_t i = 0; i < winfos.size(); ++i)
|
for (size_t i = 0; i < winfos.size(); ++i)
|
||||||
wxLogDebug(wxT("Word at (%d,%d) with len = %d and index = %d and dir = %d"),
|
wxLogDebug(wxT("Word at (%d,%d) with len = %d and index = %d and dir = %d"),
|
||||||
winfos.at(i).x,winfos.at(i).y,winfos.at(i).len, winfos.at(i).ind, int(winfos.at(i).direct));
|
winfos.at(i).x,winfos.at(i).y,winfos.at(i).len, winfos.at(i).ind, int(winfos.at(i).direct));
|
||||||
|
|
||||||
|
WorkGridType grid_work;
|
||||||
|
toWorkGridType(grid, grid_work);
|
||||||
UsedWords t_used;
|
UsedWords t_used;
|
||||||
procCross(t_used, words, grid, winfos, 0, words_out);
|
std::vector< TransedWord > words_trans_out;
|
||||||
std::reverse(words_out.begin(), words_out.end());
|
procCross(t_used, words, grid_work, winfos, 0, words_trans_out);
|
||||||
|
std::reverse(words_trans_out.begin(), words_trans_out.end());
|
||||||
|
BackedCharsTransType bctt = getFromCharsTransed(trans_type);
|
||||||
|
words_out.clear();
|
||||||
|
for (auto it = words_trans_out.begin(); it != words_trans_out.end(); ++it){
|
||||||
|
words_out.push_back(getFromTransed(*it, bctt));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CROSSGEN_HPP
|
#endif // CROSSGEN_HPP
|
||||||
|
|||||||
@@ -2,18 +2,18 @@
|
|||||||
## Auto Generated makefile by CodeLite IDE
|
## Auto Generated makefile by CodeLite IDE
|
||||||
## any manual changes will be erased
|
## any manual changes will be erased
|
||||||
##
|
##
|
||||||
## Debug
|
## Release
|
||||||
ProjectName :=wxCrossGen
|
ProjectName :=wxCrossGen
|
||||||
ConfigurationName :=Debug
|
ConfigurationName :=Release
|
||||||
WorkspacePath := "/data/Sync/SyncProjects/CrossGen"
|
WorkspacePath := "/data/Sync/SyncProjects/CrossGen"
|
||||||
ProjectPath := "/data/Sync/SyncProjects/CrossGen/wxCrossGen"
|
ProjectPath := "/data/Sync/SyncProjects/CrossGen/wxCrossGen"
|
||||||
IntermediateDirectory :=./Debug
|
IntermediateDirectory :=../Release
|
||||||
OutDir := $(IntermediateDirectory)
|
OutDir := $(IntermediateDirectory)
|
||||||
CurrentFileName :=
|
CurrentFileName :=
|
||||||
CurrentFilePath :=
|
CurrentFilePath :=
|
||||||
CurrentFileFullPath :=
|
CurrentFileFullPath :=
|
||||||
User :=Aleksey Lobanov
|
User :=Aleksey Lobanov
|
||||||
Date :=13/06/15
|
Date :=14/06/15
|
||||||
CodeLitePath :="/home/alex/.codelite"
|
CodeLitePath :="/home/alex/.codelite"
|
||||||
LinkerName :=/usr/bin/g++-4.8
|
LinkerName :=/usr/bin/g++-4.8
|
||||||
SharedObjectLinkerName :=/usr/bin/g++-4.8 -shared -fPIC
|
SharedObjectLinkerName :=/usr/bin/g++-4.8 -shared -fPIC
|
||||||
@@ -28,14 +28,14 @@ LibraryPathSwitch :=-L
|
|||||||
PreprocessorSwitch :=-D
|
PreprocessorSwitch :=-D
|
||||||
SourceSwitch :=-c
|
SourceSwitch :=-c
|
||||||
OutputFile :=$(IntermediateDirectory)/$(ProjectName).out
|
OutputFile :=$(IntermediateDirectory)/$(ProjectName).out
|
||||||
Preprocessors :=
|
Preprocessors :=$(PreprocessorSwitch)NDEBUG
|
||||||
ObjectSwitch :=-o
|
ObjectSwitch :=-o
|
||||||
ArchiveOutputSwitch :=
|
ArchiveOutputSwitch :=
|
||||||
PreprocessOnlySwitch :=-E
|
PreprocessOnlySwitch :=-E
|
||||||
ObjectsFileList :="wxCrossGen.txt"
|
ObjectsFileList :="wxCrossGen.txt"
|
||||||
PCHCompileFlags :=
|
PCHCompileFlags :=
|
||||||
MakeDirCommand :=mkdir -p
|
MakeDirCommand :=mkdir -p
|
||||||
LinkOptions := $(shell wx-config --debug=yes --libs --unicode=yes)
|
LinkOptions := -s $(shell wx-config --debug=no --libs --unicode=yes)
|
||||||
IncludePath := $(IncludeSwitch). $(IncludeSwitch)../src
|
IncludePath := $(IncludeSwitch). $(IncludeSwitch)../src
|
||||||
IncludePCH :=
|
IncludePCH :=
|
||||||
RcIncludePath :=
|
RcIncludePath :=
|
||||||
@@ -50,8 +50,8 @@ LibPath := $(LibraryPathSwitch).
|
|||||||
AR := /usr/bin/ar rcu
|
AR := /usr/bin/ar rcu
|
||||||
CXX := /usr/bin/g++-4.8
|
CXX := /usr/bin/g++-4.8
|
||||||
CC := /usr/bin/gcc-4.8
|
CC := /usr/bin/gcc-4.8
|
||||||
CXXFLAGS := -std=c++11 -g -O0 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=yes) $(Preprocessors)
|
CXXFLAGS := -std=c++11 -O2 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=no) $(Preprocessors)
|
||||||
CFLAGS := -g -O0 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=yes) $(Preprocessors)
|
CFLAGS := -O2 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=no) $(Preprocessors)
|
||||||
ASFLAGS :=
|
ASFLAGS :=
|
||||||
AS := /usr/bin/as
|
AS := /usr/bin/as
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ $(OutputFile): $(IntermediateDirectory)/.d $(Objects)
|
|||||||
$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)
|
$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)
|
||||||
|
|
||||||
$(IntermediateDirectory)/.d:
|
$(IntermediateDirectory)/.d:
|
||||||
@test -d ./Debug || $(MakeDirCommand) ./Debug
|
@test -d ../Release || $(MakeDirCommand) ../Release
|
||||||
|
|
||||||
PreBuild:
|
PreBuild:
|
||||||
|
|
||||||
@@ -101,6 +101,6 @@ $(IntermediateDirectory)/main.cpp$(PreprocessSuffix): main.cpp
|
|||||||
## Clean
|
## Clean
|
||||||
##
|
##
|
||||||
clean:
|
clean:
|
||||||
$(RM) -r ./Debug/
|
$(RM) -r ../Release/
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
./Debug/main.cpp.o
|
../Release/main.cpp.o
|
||||||
|
|||||||
Reference in New Issue
Block a user