Skip to content

Commit

Permalink
fix iter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ruoshui1126 committed Nov 5, 2013
1 parent c868cf5 commit 55ed9c4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
8 changes: 5 additions & 3 deletions src/ner/featurespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class FeatureSpaceIterator {
// should be careful about the empty dicts
}

FeatureSpaceIterator(utility::SmartMap<int> * dicts) :
FeatureSpaceIterator(utility::SmartMap<int> * dicts,int num_dicts) :
_dicts(dicts),
_num_dicts(num_dicts),
_i(0),
_state(0) {
++ (*this);
Expand Down Expand Up @@ -64,6 +65,7 @@ class FeatureSpaceIterator {

int _i;
int _state;
int _num_dicts;
utility::SmartMap<int>::const_iterator _j;
utility::SmartMap<int> * _dicts;
};
Expand Down Expand Up @@ -96,11 +98,11 @@ class FeatureSpace {
bool load(int num_labeles, std::istream & ifs);

FeatureSpaceIterator begin() {
return FeatureSpaceIterator(dicts);
return FeatureSpaceIterator(dicts,_num_dicts);
}

FeatureSpaceIterator end() {
return FeatureSpaceIterator(dicts + _num_dicts);
return FeatureSpaceIterator(dicts + _num_dicts,_num_dicts);
}
private:
int _offset;
Expand Down
20 changes: 12 additions & 8 deletions src/postagger/featurespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class FeatureSpaceIterator {
// should be careful about the empty dicts
}

FeatureSpaceIterator(utility::SmartMap<int> * dicts) :
_dicts(dicts),
FeatureSpaceIterator(utility::SmartMap<int> * dicts,int num_dicts) :
_dicts(dicts),
_num_dicts(num_dicts),
_i(0),
_state(0) {
++ (*this);
Expand Down Expand Up @@ -48,11 +49,12 @@ class FeatureSpaceIterator {
void operator ++() {
switch (_state) {
case 0:
for (_i = 0; ; ++ _i) {
if (_dicts[_i].begin() == _dicts[_i].end()) {
for (_i = 0;_i<_num_dicts ; ++ _i) {
/*if (_dicts[_i].begin() == _dicts[_i].end()) {
_state = 1;
return;
}
//return;
continue;
}*/
for (_j = _dicts[_i].begin(); _j != _dicts[_i].end(); ++ _j) {
_state = 1;
return;
Expand All @@ -64,6 +66,7 @@ class FeatureSpaceIterator {

int _i;
int _state;
int _num_dicts;
utility::SmartMap<int>::const_iterator _j;
utility::SmartMap<int> * _dicts;
};
Expand All @@ -79,6 +82,7 @@ class FeatureSpace {
int num_features();
int dim();
void set_num_labels(int num_labeles);
int get_offset();

/*
* dump the feature space to a output stream
Expand All @@ -96,11 +100,11 @@ class FeatureSpace {
bool load(int num_labeles, std::istream & ifs);

FeatureSpaceIterator begin() {
return FeatureSpaceIterator(dicts);
return FeatureSpaceIterator(dicts,_num_dicts);
}

FeatureSpaceIterator end() {
return FeatureSpaceIterator(dicts + _num_dicts);
return FeatureSpaceIterator(dicts + _num_dicts,_num_dicts);
}

private:
Expand Down
16 changes: 10 additions & 6 deletions src/segmentor/featurespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class FeatureSpaceIterator {
// should be careful about the empty dicts
}

FeatureSpaceIterator(utility::SmartMap<int> * dicts) :
FeatureSpaceIterator(utility::SmartMap<int> * dicts,int num_dicts) :
_dicts(dicts),
_num_dicts(num_dicts),
_i(0),
_state(0) {
++ (*this);
Expand Down Expand Up @@ -48,11 +49,11 @@ class FeatureSpaceIterator {
void operator ++() {
switch (_state) {
case 0:
for (_i = 0; ; ++ _i) {
if (_dicts[_i].begin() == _dicts[_i].end()) {
for (_i = 0;_i<_num_dicts ; ++ _i) {
/* if (_dicts[_i].begin() == _dicts[_i].end()) {
_state = 1;
return;
}
}*/
for (_j = _dicts[_i].begin(); _j != _dicts[_i].end(); ++ _j) {
_state = 1;
return;
Expand All @@ -64,6 +65,7 @@ class FeatureSpaceIterator {

int _i;
int _state;
int _num_dicts;
utility::SmartMap<int>::const_iterator _j;
utility::SmartMap<int> * _dicts;
};
Expand All @@ -77,7 +79,9 @@ class FeatureSpace {
int index(int tid, const char * key, int lid = 0);
int index(int prev_lid, int lid);
int num_features();
int id_label_to_id(int idx);
int dim();
int get_offset();
void set_num_labels(int num_labeles);

/*
Expand All @@ -96,11 +100,11 @@ class FeatureSpace {
bool load(int num_labeles, std::istream & ifs);

FeatureSpaceIterator begin() {
return FeatureSpaceIterator(dicts);
return FeatureSpaceIterator(dicts,_num_dicts);
}

FeatureSpaceIterator end() {
return FeatureSpaceIterator(dicts + _num_dicts);
return FeatureSpaceIterator(dicts + _num_dicts,_num_dicts);
}
private:
int _offset;
Expand Down

0 comments on commit 55ed9c4

Please sign in to comment.