Use C++-11 code instead of TessCallback for PointerVector::compact

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2019-07-03 16:42:52 +02:00
parent cc0405298b
commit c33b05be55
2 changed files with 5 additions and 7 deletions

View File

@ -28,7 +28,6 @@
#include "helpers.h"
#include "serialis.h"
#include "strngs.h"
#include "tesscallback.h"
// Use PointerVector<T> below in preference to GenericVector<T*>, as that
// provides automatic deletion of pointers, [De]Serialize that works, and
@ -490,17 +489,17 @@ class PointerVector : public GenericVector<T*> {
// Compact the vector by deleting elements for which delete_cb returns
// true. delete_cb is a permanent callback and will be deleted.
void compact(TessResultCallback1<bool, const T*>* delete_cb) {
void compact(std::function<bool(const T*)> delete_cb) {
int new_size = 0;
int old_index = 0;
// Until the callback returns true, the elements stay the same.
while (old_index < GenericVector<T*>::size_used_ &&
!delete_cb->Run(GenericVector<T*>::data_[old_index++])) {
!delete_cb(GenericVector<T*>::data_[old_index++])) {
++new_size;
}
// Now just copy anything else that gets false from delete_cb.
for (; old_index < GenericVector<T*>::size_used_; ++old_index) {
if (!delete_cb->Run(GenericVector<T*>::data_[old_index])) {
if (!delete_cb(GenericVector<T*>::data_[old_index])) {
GenericVector<T*>::data_[new_size++] =
GenericVector<T*>::data_[old_index];
} else {
@ -508,7 +507,6 @@ class PointerVector : public GenericVector<T*> {
}
}
GenericVector<T*>::size_used_ = new_size;
delete delete_cb;
}
// Clear the array, calling the clear callback function if any.

View File

@ -495,8 +495,8 @@ void TrainingSampleSet::KillSample(TrainingSample* sample) {
// Deletes all samples with zero features marked by KillSample.
void TrainingSampleSet::DeleteDeadSamples() {
samples_.compact(
NewPermanentTessCallback(this, &TrainingSampleSet::DeleteableSample));
using namespace std::placeholders; // for _1
samples_.compact(std::bind(&TrainingSampleSet::DeleteableSample, this, _1));
num_raw_samples_ = samples_.size();
// Samples must be re-organized now we have deleted a few.
}