summaryrefslogtreecommitdiff
path: root/decoder/sparse_vector.h
diff options
context:
space:
mode:
authorChris Dyer <redpony@gmail.com>2009-12-18 01:27:19 -0500
committerChris Dyer <redpony@gmail.com>2009-12-18 01:27:19 -0500
commit1aac806af7785ab440d300ca5cfa8833e3ed61d3 (patch)
tree4a2ffa484af029ebc542f2cdf7bb6da93325b29a /decoder/sparse_vector.h
parent40ac2d31391c27b168b0294e7683cb69da29f868 (diff)
add support for freezing the feature set to a user-specified list, even if feature detectors create additional features
Diffstat (limited to 'decoder/sparse_vector.h')
-rw-r--r--decoder/sparse_vector.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/decoder/sparse_vector.h b/decoder/sparse_vector.h
index 6a8c9bf4..2b4a63a9 100644
--- a/decoder/sparse_vector.h
+++ b/decoder/sparse_vector.h
@@ -185,10 +185,15 @@ public:
}
std::ostream &operator<<(std::ostream &out) const {
+ bool first = true;
for (typename std::map<int, T>::const_iterator
- it = _values.begin(); it != _values.end(); ++it)
- out << (it == _values.begin() ? "" : ";")
- << FD::Convert(it->first) << '=' << it->second;
+ it = _values.begin(); it != _values.end(); ++it) {
+ // by definition feature id 0 is a dummy value
+ if (it->first == 0) continue;
+ out << (first ? "" : ";")
+ << FD::Convert(it->first) << '=' << it->second;
+ first = false;
+ }
return out;
}
@@ -216,6 +221,9 @@ public:
void clear() {
_values.clear();
}
+ void clear_value(int index) {
+ _values.erase(index);
+ }
void swap(SparseVector<T>& other) {
_values.swap(other._values);