2
* Copyright 2013, GitHub, Inc
3
* Copyright 2009-2013, Daniel Lemire, Cliff Moon,
4
* David McIntosh, Robert Becho, Google Inc. and Veronika Zenz
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, see <http://www.gnu.org/licenses/>.
19
#include "git-compat-util.h"
23
static inline int next_word(struct rlw_iterator *it)
25
if (it->pointer >= it->size)
28
it->rlw.word = &it->buffer[it->pointer];
29
it->pointer += rlw_get_literal_words(it->rlw.word) + 1;
31
it->rlw.literal_words = rlw_get_literal_words(it->rlw.word);
32
it->rlw.running_len = rlw_get_running_len(it->rlw.word);
33
it->rlw.running_bit = rlw_get_run_bit(it->rlw.word);
34
it->rlw.literal_word_offset = 0;
39
void rlwit_init(struct rlw_iterator *it, struct ewah_bitmap *from_ewah)
41
it->buffer = from_ewah->buffer;
42
it->size = from_ewah->buffer_size;
47
it->literal_word_start = rlwit_literal_words(it) +
48
it->rlw.literal_word_offset;
51
void rlwit_discard_first_words(struct rlw_iterator *it, size_t x)
56
if (it->rlw.running_len > x) {
57
it->rlw.running_len -= x;
61
x -= it->rlw.running_len;
62
it->rlw.running_len = 0;
64
discard = (x > it->rlw.literal_words) ? it->rlw.literal_words : x;
66
it->literal_word_start += discard;
67
it->rlw.literal_words -= discard;
70
if (x > 0 || rlwit_word_size(it) == 0) {
74
it->literal_word_start =
75
rlwit_literal_words(it) + it->rlw.literal_word_offset;
80
size_t rlwit_discharge(
81
struct rlw_iterator *it, struct ewah_bitmap *out, size_t max, int negate)
85
while (index < max && rlwit_word_size(it) > 0) {
86
size_t pd, pl = it->rlw.running_len;
91
ewah_add_empty_words(out, it->rlw.running_bit ^ negate, pl);
94
pd = it->rlw.literal_words;
98
ewah_add_dirty_words(out,
99
it->buffer + it->literal_word_start, pd, negate);
101
rlwit_discard_first_words(it, pd + pl);