Fixed the operation of --head and --tail
This commit is contained in:
parent
0efe0c63ce
commit
afe3a899c6
2 changed files with 28 additions and 16 deletions
|
|
@ -61,22 +61,22 @@ void truncate_xacts::flush()
|
||||||
if (! posts.size())
|
if (! posts.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
xact_t * last_xact = (*posts.begin())->xact;
|
xact_t * xact = (*posts.begin())->xact;
|
||||||
|
|
||||||
int l = 0;
|
int l = 0;
|
||||||
foreach (post_t * post, posts)
|
foreach (post_t * post, posts)
|
||||||
if (last_xact != post->xact) {
|
if (xact != post->xact) {
|
||||||
l++;
|
l++;
|
||||||
last_xact = post->xact;
|
xact = post->xact;
|
||||||
}
|
}
|
||||||
l++;
|
l++;
|
||||||
|
|
||||||
last_xact = (*posts.begin())->xact;
|
xact = (*posts.begin())->xact;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (post_t * post, posts) {
|
foreach (post_t * post, posts) {
|
||||||
if (last_xact != post->xact) {
|
if (xact != post->xact) {
|
||||||
last_xact = post->xact;
|
xact = post->xact;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,6 +103,21 @@ void truncate_xacts::flush()
|
||||||
item_handler<post_t>::flush();
|
item_handler<post_t>::flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void truncate_xacts::operator()(post_t& post)
|
||||||
|
{
|
||||||
|
if (last_xact != post.xact) {
|
||||||
|
if (last_xact)
|
||||||
|
xacts_seen++;
|
||||||
|
last_xact = post.xact;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tail_count == 0 && head_count > 0 &&
|
||||||
|
static_cast<int>(xacts_seen) >= head_count)
|
||||||
|
return;
|
||||||
|
|
||||||
|
posts.push_back(&post);
|
||||||
|
}
|
||||||
|
|
||||||
void set_account_value::operator()(post_t& post)
|
void set_account_value::operator()(post_t& post)
|
||||||
{
|
{
|
||||||
account_t * acct = post.reported_account();
|
account_t * acct = post.reported_account();
|
||||||
|
|
|
||||||
|
|
@ -160,14 +160,16 @@ class truncate_xacts : public item_handler<post_t>
|
||||||
int tail_count;
|
int tail_count;
|
||||||
|
|
||||||
posts_list posts;
|
posts_list posts;
|
||||||
|
std::size_t xacts_seen;
|
||||||
|
xact_t * last_xact;
|
||||||
|
|
||||||
truncate_xacts();
|
truncate_xacts();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
truncate_xacts(post_handler_ptr handler,
|
truncate_xacts(post_handler_ptr handler, int _head_count, int _tail_count)
|
||||||
int _head_count, int _tail_count)
|
|
||||||
: item_handler<post_t>(handler),
|
: item_handler<post_t>(handler),
|
||||||
head_count(_head_count), tail_count(_tail_count) {
|
head_count(_head_count), tail_count(_tail_count),
|
||||||
|
xacts_seen(0), last_xact(NULL) {
|
||||||
TRACE_CTOR(truncate_xacts, "post_handler_ptr, int, int");
|
TRACE_CTOR(truncate_xacts, "post_handler_ptr, int, int");
|
||||||
}
|
}
|
||||||
virtual ~truncate_xacts() {
|
virtual ~truncate_xacts() {
|
||||||
|
|
@ -175,12 +177,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void flush();
|
virtual void flush();
|
||||||
|
virtual void operator()(post_t& post);
|
||||||
virtual void operator()(post_t& post) {
|
|
||||||
if (! (tail_count == 0 && head_count > 0 &&
|
|
||||||
static_cast<int>(posts.size()) >= head_count))
|
|
||||||
posts.push_back(&post);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue