Some optimizing changes in generateCross function.

We can use caching of generated AllWords.
This commit is contained in:
2015-06-16 10:51:46 +03:00
parent 83bdef4bfa
commit ef0efd652a
7 changed files with 25 additions and 36 deletions

View File

@@ -13,7 +13,7 @@ CurrentFileName :=
CurrentFilePath := CurrentFilePath :=
CurrentFileFullPath := CurrentFileFullPath :=
User :=Aleksey Lobanov User :=Aleksey Lobanov
Date :=14/06/15 Date :=16/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

View File

@@ -63,8 +63,11 @@ int main(int argc, char **argv) {
std::vector< wxString > words_out; std::vector< wxString > words_out;
DictType dict; DictType dict;
GridType grid; GridType grid;
AllWordsType all_words;
CharsTransType trans_type;
readDict(dict_path, dict); readDict(dict_path, dict);
generateAllWords(dict, all_words, trans_type);
readGrid(grid_path, grid); readGrid(grid_path, grid);
if ( is_rand ) if ( is_rand )
@@ -75,7 +78,7 @@ int main(int argc, char **argv) {
srand(42); srand(42);
words_out.clear(); words_out.clear();
durs.at(i) = wxGetLocalTimeMillis(); durs.at(i) = wxGetLocalTimeMillis();
generateCross(grid,dict,words_out); generateCross(grid,all_words,trans_type,words_out);
if ( words_out.size() == 0 ) if ( words_out.size() == 0 )
wxPrintf(wxT("Error in creating #%i!\n"),i+1); wxPrintf(wxT("Error in creating #%i!\n"),i+1);
durs.at(i) = wxGetLocalTimeMillis() - durs.at(i); durs.at(i) = wxGetLocalTimeMillis() - durs.at(i);

View File

@@ -179,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, WorkGridType grid, bool procCross(UsedWords used, const AllWordsType &words, WorkGridType grid,
std::vector<WordInfo> &winfos, size_t cur_word_ind, std::vector<TransedWord> &out){ const std::vector<WordInfo> &winfos, const 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);
@@ -230,10 +230,9 @@ bool procCross(UsedWords used, AllWordsType &words, WorkGridType grid,
return false; return false;
} }
void generateCross(GridType &grid, const DictType &dict, std::vector<wxString> &words_out){ void generateCross(const GridType &grid, const AllWordsType &words,
AllWordsType words; const CharsTransType &trans_type, std::vector<wxString> &words_out){
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)

View File

@@ -159,6 +159,7 @@ void MainFrame::SetGridImage(GridType &grid, size_t w) {
void MainFrame::OnbtnGenerateClick(wxCommandEvent &event) { void MainFrame::OnbtnGenerateClick(wxCommandEvent &event) {
if ( !_isDictLoaded ) { if ( !_isDictLoaded ) {
readDict(wxT("big_cross_ru.txt"), _dict); readDict(wxT("big_cross_ru.txt"), _dict);
generateAllWords(_dict, _allWords, _transType);
_isDictLoaded = true; _isDictLoaded = true;
} }
@@ -170,7 +171,7 @@ void MainFrame::OnbtnGenerateClick(wxCommandEvent &event) {
} }
readGrid(tPath->GetValue(), grid); readGrid(tPath->GetValue(), grid);
try{ try{
generateCross(grid,_dict,words_out); generateCross(grid, _allWords, _transType, words_out);
_words.clear(); _words.clear();
_words = words_out; _words = words_out;

View File

@@ -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
## ##
## Release ## Debug
ProjectName :=wxCrossGen ProjectName :=wxCrossGen
ConfigurationName :=Release ConfigurationName :=Debug
WorkspacePath := "/data/Sync/SyncProjects/CrossGen" WorkspacePath := "/data/Sync/SyncProjects/CrossGen"
ProjectPath := "/data/Sync/SyncProjects/CrossGen/wxCrossGen" ProjectPath := "/data/Sync/SyncProjects/CrossGen/wxCrossGen"
IntermediateDirectory :=../Release IntermediateDirectory :=./Debug
OutDir := $(IntermediateDirectory) OutDir := $(IntermediateDirectory)
CurrentFileName := CurrentFileName :=
CurrentFilePath := CurrentFilePath :=
CurrentFileFullPath := CurrentFileFullPath :=
User :=Aleksey Lobanov User :=Aleksey Lobanov
Date :=15/06/15 Date :=16/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 :=$(PreprocessorSwitch)NDEBUG Preprocessors :=
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 := -s $(shell wx-config --debug=no --libs --unicode=yes) LinkOptions := $(shell wx-config --debug=yes --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 -O2 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=no) $(Preprocessors) CXXFLAGS := -std=c++11 -g -O0 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=yes) $(Preprocessors)
CFLAGS := -O2 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=no) $(Preprocessors) CFLAGS := -g -O0 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=yes) $(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 ../Release || $(MakeDirCommand) ../Release @test -d ./Debug || $(MakeDirCommand) ./Debug
PreBuild: PreBuild:
@@ -101,6 +101,6 @@ $(IntermediateDirectory)/main.cpp$(PreprocessSuffix): main.cpp
## Clean ## Clean
## ##
clean: clean:
$(RM) -r ../Release/ $(RM) -r ./Debug/

View File

@@ -1 +1 @@
../Release/main.cpp.o ./Debug/main.cpp.o

View File

@@ -1,13 +1,4 @@
// -*- C++ -*-
//
// generated by wxGlade 0.6.8 on Wed May 20 12:40:03 2015 // generated by wxGlade 0.6.8 on Wed May 20 12:40:03 2015
//
// Example for compiling a single file project under Linux using g++:
// g++ MyApp.cpp $(wx-config --libs) $(wx-config --cxxflags) -o MyApp
//
// Example for compiling a multi file project under Linux using g++:
// g++ main.cpp $(wx-config --libs) $(wx-config --cxxflags) -o MyApp Dialog1.cpp Frame1.cpp
//
#ifndef WXGUI_HPP #ifndef WXGUI_HPP
#define WXGUI_HPP #define WXGUI_HPP
@@ -24,13 +15,6 @@
#endif #endif
// begin wxGlade: ::dependencies
// end wxGlade
// begin wxGlade: ::extracode
// end wxGlade
class MainFrame: public wxFrame { class MainFrame: public wxFrame {
public: public:
// begin wxGlade: MainFrame::ids // begin wxGlade: MainFrame::ids
@@ -48,6 +32,8 @@ protected:
std::vector<wxString> _words; std::vector<wxString> _words;
DictType _dict; DictType _dict;
bool _isDictLoaded; bool _isDictLoaded;
AllWordsType _allWords;
CharsTransType _transType;
// begin wxGlade: MainFrame::attributes // begin wxGlade: MainFrame::attributes
wxStaticText* label_1; wxStaticText* label_1;
wxTextCtrl* tPath; wxTextCtrl* tPath;