Coverage Report

Created: 2025-12-31 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/git/ewah/ewah_rlw.c
Line
Count
Source
1
/**
2
 * Copyright 2013, GitHub, Inc
3
 * Copyright 2009-2013, Daniel Lemire, Cliff Moon,
4
 *  David McIntosh, Robert Becho, Google Inc. and Veronika Zenz
5
 *
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.
10
 *
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.
15
 *
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/>.
18
 */
19
20
#define DISABLE_SIGN_COMPARE_WARNINGS
21
22
#include "git-compat-util.h"
23
#include "ewok.h"
24
#include "ewok_rlw.h"
25
26
static inline int next_word(struct rlw_iterator *it)
27
0
{
28
0
  if (it->pointer >= it->size)
29
0
    return 0;
30
31
0
  it->rlw.word = &it->buffer[it->pointer];
32
0
  it->pointer += rlw_get_literal_words(it->rlw.word) + 1;
33
34
0
  it->rlw.literal_words = rlw_get_literal_words(it->rlw.word);
35
0
  it->rlw.running_len = rlw_get_running_len(it->rlw.word);
36
0
  it->rlw.running_bit = rlw_get_run_bit(it->rlw.word);
37
0
  it->rlw.literal_word_offset = 0;
38
39
0
  return 1;
40
0
}
41
42
void rlwit_init(struct rlw_iterator *it, struct ewah_bitmap *from_ewah)
43
0
{
44
0
  it->buffer = from_ewah->buffer;
45
0
  it->size = from_ewah->buffer_size;
46
0
  it->pointer = 0;
47
48
0
  next_word(it);
49
50
0
  it->literal_word_start = rlwit_literal_words(it) +
51
0
    it->rlw.literal_word_offset;
52
0
}
53
54
void rlwit_discard_first_words(struct rlw_iterator *it, size_t x)
55
0
{
56
0
  while (x > 0) {
57
0
    size_t discard;
58
59
0
    if (it->rlw.running_len > x) {
60
0
      it->rlw.running_len -= x;
61
0
      return;
62
0
    }
63
64
0
    x -= it->rlw.running_len;
65
0
    it->rlw.running_len = 0;
66
67
0
    discard = (x > it->rlw.literal_words) ? it->rlw.literal_words : x;
68
69
0
    it->literal_word_start += discard;
70
0
    it->rlw.literal_words -= discard;
71
0
    x -= discard;
72
73
0
    if (x > 0 || rlwit_word_size(it) == 0) {
74
0
      if (!next_word(it))
75
0
        break;
76
77
0
      it->literal_word_start =
78
0
        rlwit_literal_words(it) + it->rlw.literal_word_offset;
79
0
    }
80
0
  }
81
0
}
82
83
size_t rlwit_discharge(
84
  struct rlw_iterator *it, struct ewah_bitmap *out, size_t max, int negate)
85
0
{
86
0
  size_t index = 0;
87
88
0
  while (index < max && rlwit_word_size(it) > 0) {
89
0
    size_t pd, pl = it->rlw.running_len;
90
91
0
    if (index + pl > max)
92
0
      pl = max - index;
93
94
0
    ewah_add_empty_words(out, it->rlw.running_bit ^ negate, pl);
95
0
    index += pl;
96
97
0
    pd = it->rlw.literal_words;
98
0
    if (pd + index > max)
99
0
      pd = max - index;
100
101
0
    ewah_add_dirty_words(out,
102
0
      it->buffer + it->literal_word_start, pd, negate);
103
104
0
    rlwit_discard_first_words(it, pd + pl);
105
0
    index += pd;
106
0
  }
107
108
0
  return index;
109
0
}