Skip to content

Commit

Permalink
Getting rid of remaining stringstreams in data reading functions #69
Browse files Browse the repository at this point in the history
  • Loading branch information
searchivairus committed Jan 8, 2018
1 parent df685db commit e34ebb0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
19 changes: 18 additions & 1 deletion similarity_search/src/space/space_bit_hamming.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "permutation_utils.h"
#include "logging.h"
#include "distcomp.h"
#include "read_data.h"
#include "experimentconf.h"

namespace similarity {
Expand Down Expand Up @@ -51,13 +52,15 @@ void SpaceBitHamming::ReadBitMaskVect(std::string line, LabelType& label, std::v

str.exceptions(std::ios::badbit);

unsigned val;

ReplaceSomePunct(line);

vector<PivotIdType> v;

#if 0
try {
unsigned val;

while (str >> val) {
if (val != 0 && val != 1) {
throw runtime_error("Only zeros and ones are allowed");
Expand All @@ -70,6 +73,20 @@ void SpaceBitHamming::ReadBitMaskVect(std::string line, LabelType& label, std::v
LOG(LIB_ERROR) << err.stream().str();
THROW_RUNTIME_ERR(err);
}
#else
if (!ReadVecDataEfficiently(line, v)) {
PREPARE_RUNTIME_ERR(err) << "Failed to parse the line: '" << line << "'";
LOG(LIB_ERROR) << err.stream().str();
THROW_RUNTIME_ERR(err);
}
for (auto val : v) {
if (val != 0 && val != 1) {
PREPARE_RUNTIME_ERR(err) << "Only zeros and ones are allowed, offending line: '" << line << "'";
LOG(LIB_ERROR) << err.stream().str();
THROW_RUNTIME_ERR(err);
}
}
#endif
Binarize(v, 1, binVect); // Create the binary vector
binVect.push_back(v.size()); // Put the number of elements in the end
}
Expand Down
9 changes: 9 additions & 0 deletions similarity_search/src/space/space_sparse_jaccard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "logging.h"
#include "distcomp.h"
#include "experimentconf.h"
#include "read_data.h"
#include "space/space_sparse_jaccard.h"

namespace similarity {
Expand All @@ -40,6 +41,7 @@ static void ReadIdList(string line, LabelType& label, vector<IdType>& v)

label = Object::extractLabel(line);

#if 0
ReplaceSomePunct(line);
stringstream str(line);

Expand All @@ -56,6 +58,13 @@ static void ReadIdList(string line, LabelType& label, vector<IdType>& v)
LOG(LIB_ERROR) << "Exception: " << e.what();
LOG(LIB_FATAL) << "Failed to parse the line: '" << line << "'";
}
#else
if (!ReadVecDataEfficiently(line, v)) {
PREPARE_RUNTIME_ERR(err) << "Failed to parse the line: '" << line << "'";
LOG(LIB_ERROR) << err.stream().str();
THROW_RUNTIME_ERR(err);
}
#endif

sort(v.begin(), v.end());
}
Expand Down

0 comments on commit e34ebb0

Please sign in to comment.