File: 222.patch

package info (click to toggle)
lucene%2B%2B 3.0.9-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,896 kB
  • sloc: cpp: 174,280; ansic: 26,951; python: 8,626; sh: 524; makefile: 31
file content (484 lines) | stat: -rw-r--r-- 16,615 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
From 146a62a4ee84ad8286c13bdd50f174fc5a614d43 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
 <congdanhqx@gmail.com>
Date: Fri, 5 Dec 2025 10:37:48 +0700
Subject: [PATCH 1/2] BitSet: Partial fix for Boost 1.90

---
 include/lucene++/BitSet.h |  8 ++++-
 src/core/util/BitSet.cpp  | 72 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/include/lucene++/BitSet.h b/include/lucene++/BitSet.h
index e06e6c7b..d07f12c5 100644
--- a/include/lucene++/BitSet.h
+++ b/include/lucene++/BitSet.h
@@ -8,6 +8,7 @@
 #define BITSET_H
 
 #include <boost/dynamic_bitset.hpp>
+#include <boost/version.hpp>
 #include "LuceneObject.h"
 
 namespace Lucene {
@@ -22,9 +23,14 @@ class LPPAPI BitSet : public LuceneObject {
 protected:
     typedef boost::dynamic_bitset<uint64_t> bitset_type;
     bitset_type bitSet;
+#if BOOST_VERSION >= 109000
+    typedef const bitset_type& get_bits_result;
+#else
+    typedef const uint64_t* get_bits_result;
+#endif
 
 public:
-    const uint64_t* getBits();
+    get_bits_result getBits();
     void clear();
     void clear(uint32_t bitIndex);
     void fastClear(uint32_t bitIndex);
diff --git a/src/core/util/BitSet.cpp b/src/core/util/BitSet.cpp
index 6eb9d943..bff757bb 100644
--- a/src/core/util/BitSet.cpp
+++ b/src/core/util/BitSet.cpp
@@ -7,6 +7,8 @@
 #include "LuceneInc.h"
 #include "BitSet.h"
 #include "BitUtil.h"
+#include <boost/version.hpp>
+#include <boost/iterator/function_output_iterator.hpp>
 
 namespace Lucene {
 
@@ -16,8 +18,12 @@ BitSet::BitSet(uint32_t size) : bitSet(size) {
 BitSet::~BitSet() {
 }
 
-const uint64_t* BitSet::getBits() {
+BitSet::get_bits_result BitSet::getBits() {
+#if BOOST_VERSION < 109000
     return bitSet.empty() ? NULL : static_cast<const uint64_t*>(&bitSet.m_bits[0]);
+#else
+    return bitSet;
+#endif
 }
 
 void BitSet::clear() {
@@ -151,6 +157,11 @@ int32_t BitSet::nextSetBit(uint32_t fromIndex) const {
 }
 
 void BitSet::_and(const BitSetPtr& set) {
+#if BOOST_VERSION >= 108900
+    bitset_type other = set->bitSet;
+    other.resize(bitSet.size());
+    bitSet &= other;
+#else
     bitset_type::size_type minBlocks = std::min(bitSet.num_blocks(), set->bitSet.num_blocks());
     for (bitset_type::size_type i = 0; i < minBlocks; ++i) {
         bitSet.m_bits[i] &= set->bitSet.m_bits[i];
@@ -158,9 +169,20 @@ void BitSet::_and(const BitSetPtr& set) {
     if (bitSet.num_blocks() > minBlocks) {
         std::fill(bitSet.m_bits.begin() + minBlocks, bitSet.m_bits.end(), bitset_type::block_type(0));
     }
+#endif
 }
 
 void BitSet::_or(const BitSetPtr& set) {
+#if BOOST_VERSION >= 108900
+    if (set->bitSet.size() > bitSet.size()) {
+        resize(set->bitSet.size());
+        bitSet |= set->bitSet;
+    } else {
+        bitset_type other = set->bitSet;
+        other.resize(bitSet.size());
+        bitSet |= other;
+    }
+#else
     bitset_type::size_type minBlocks = std::min(bitSet.num_blocks(), set->bitSet.num_blocks());
     if (set->bitSet.size() > bitSet.size()) {
         resize(set->bitSet.size());
@@ -171,9 +193,20 @@ void BitSet::_or(const BitSetPtr& set) {
     if (bitSet.num_blocks() > minBlocks) {
         std::copy(set->bitSet.m_bits.begin() + minBlocks, set->bitSet.m_bits.end(), bitSet.m_bits.begin() + minBlocks);
     }
+#endif
 }
 
 void BitSet::_xor(const BitSetPtr& set) {
+#if BOOST_VERSION >= 108900
+    if (set->bitSet.size() > bitSet.size()) {
+        resize(set->bitSet.size());
+        bitSet ^= set->bitSet;
+    } else {
+        bitset_type other = set->bitSet;
+        other.resize(bitSet.size());
+        bitSet ^= other;
+    }
+#else
     bitset_type::size_type minBlocks = std::min(bitSet.num_blocks(), set->bitSet.num_blocks());
     if (set->bitSet.size() > bitSet.size()) {
         resize(set->bitSet.size());
@@ -184,13 +217,20 @@ void BitSet::_xor(const BitSetPtr& set) {
     if (bitSet.num_blocks() > minBlocks) {
         std::copy(set->bitSet.m_bits.begin() + minBlocks, set->bitSet.m_bits.end(), bitSet.m_bits.begin() + minBlocks);
     }
+#endif
 }
 
 void BitSet::andNot(const BitSetPtr& set) {
+#if BOOST_VERSION >= 108900
+    bitset_type other = set->bitSet;
+    other.resize(bitSet.size());
+    bitSet &= other.flip();
+#else
     bitset_type::size_type minBlocks = std::min(bitSet.num_blocks(), set->bitSet.num_blocks());
     for (bitset_type::size_type i = 0; i < minBlocks; ++i) {
         bitSet.m_bits[i] &= ~set->bitSet.m_bits[i];
     }
+#endif
 }
 
 bool BitSet::intersectsBitSet(const BitSetPtr& set) const {
@@ -198,10 +238,17 @@ bool BitSet::intersectsBitSet(const BitSetPtr& set) const {
 }
 
 uint32_t BitSet::cardinality() {
+#if BOOST_VERSION >= 108900
+    return bitSet.count();
+#else
     return bitSet.num_blocks() == 0 ? 0 : (uint32_t)BitUtil::pop_array((int64_t*)getBits(), 0, bitSet.num_blocks());
+#endif
 }
 
 void BitSet::resize(uint32_t size) {
+#if BOOST_VERSION >= 108900
+    bitSet.resize(size);
+#else
     bitset_type::size_type old_num_blocks = bitSet.num_blocks();
     bitset_type::size_type required_blocks = bitSet.calc_num_blocks(size);
     if (required_blocks != old_num_blocks) {
@@ -212,6 +259,7 @@ void BitSet::resize(uint32_t size) {
     if (extra_bits != 0) {
         bitSet.m_bits.back() &= ~(~static_cast<bitset_type::block_type>(0) << extra_bits);
     }
+#endif
 }
 
 bool BitSet::equals(const LuceneObjectPtr& other) {
@@ -224,6 +272,18 @@ bool BitSet::equals(const LuceneObjectPtr& other) {
     }
     BitSetPtr first = bitSet.num_blocks() < otherBitSet->bitSet.num_blocks() ? otherBitSet : shared_from_this();
     BitSetPtr second = bitSet.num_blocks() < otherBitSet->bitSet.num_blocks() ? shared_from_this() : otherBitSet;
+#if BOOST_VERSION >= 108900
+    bitset_type::size_type f = first->bitSet.find_first();
+    bitset_type::size_type s = second->bitSet.find_first();
+    while (f == s) {
+        if (f == bitset_type::npos) {
+            return true;
+        }
+        f = first->bitSet.find_next(f);
+        s = second->bitSet.find_next(s);
+    }
+    return false;
+#else
     bitset_type::size_type firstLength = first->bitSet.num_blocks();
     bitset_type::size_type secondLength = second->bitSet.num_blocks();
     for (bitset_type::size_type i = secondLength; i < firstLength; ++i) {
@@ -237,18 +297,28 @@ bool BitSet::equals(const LuceneObjectPtr& other) {
         }
     }
     return true;
+#endif
 }
 
 int32_t BitSet::hashCode() {
     // Start with a zero hash and use a mix that results in zero if the input is zero.
     // This effectively truncates trailing zeros without an explicit check.
     int64_t hash = 0;
+#if BOOST_VERSION >= 108900
+    to_block_range(bitSet, boost::make_function_output_iterator(
+        [&hash](bitset_type::block_type block) {
+            hash ^= block;
+            hash = (hash << 1) | (hash >> 63); // rotate left
+        }
+    ));
+#else
     uint32_t maxSize = bitSet.num_blocks();
     const uint64_t* bits = getBits();
     for (uint32_t bit = 0; bit < maxSize; ++bit) {
         hash ^= bits[bit];
         hash = (hash << 1) | (hash >> 63); // rotate left
     }
+#endif
     // Fold leftmost bits into right and add a constant to prevent empty sets from
     // returning 0, which is too common.
     return (int32_t)((hash >> 32) ^ hash) + 0x98761234;

From 55a1238e23c0f98ff375acaf8bb4f6ebba9f2b72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
 <congdanhqx@gmail.com>
Date: Fri, 5 Dec 2025 11:19:08 +0700
Subject: [PATCH 2/2] BitSet: prefer builtin boost function

---
 src/core/util/BitSet.cpp | 126 +++++++--------------------------------
 1 file changed, 23 insertions(+), 103 deletions(-)

diff --git a/src/core/util/BitSet.cpp b/src/core/util/BitSet.cpp
index bff757bb..c2fa941b 100644
--- a/src/core/util/BitSet.cpp
+++ b/src/core/util/BitSet.cpp
@@ -41,16 +41,20 @@ void BitSet::fastClear(uint32_t bitIndex) {
 }
 
 void BitSet::clear(uint32_t fromIndex, uint32_t toIndex) {
+#if BOOST_VERSION >= 106900
+    fromIndex = std::min<bitset_type::size_type>(fromIndex, bitSet.size());
+    toIndex = std::min<bitset_type::size_type>(toIndex, bitSet.size());
+    bitSet.reset(fromIndex, toIndex - fromIndex);
+#else
     toIndex = std::min(toIndex, (uint32_t)bitSet.size());
     for (bitset_type::size_type i = std::min(fromIndex, (uint32_t)bitSet.size()); i < toIndex; ++i) {
         bitSet.set(i, false);
     }
+#endif
 }
 
 void BitSet::fastClear(uint32_t fromIndex, uint32_t toIndex) {
-    for (bitset_type::size_type i = fromIndex; i < toIndex; ++i) {
-        bitSet.set(i, false);
-    }
+    fastSet(fromIndex, toIndex, false);
 }
 
 void BitSet::set(uint32_t bitIndex) {
@@ -76,33 +80,28 @@ void BitSet::fastSet(uint32_t bitIndex, bool value) {
 }
 
 void BitSet::set(uint32_t fromIndex, uint32_t toIndex) {
-    if (toIndex >= bitSet.size()) {
-        resize(toIndex + 1);
-    }
-    for (bitset_type::size_type i = fromIndex; i < toIndex; ++i) {
-        bitSet.set(i, true);
-    }
+    set(fromIndex, toIndex, true);
 }
 
 void BitSet::fastSet(uint32_t fromIndex, uint32_t toIndex) {
-    for (bitset_type::size_type i = fromIndex; i < toIndex; ++i) {
-        bitSet.set(i, true);
-    }
+    fastSet(fromIndex, toIndex, true);
 }
 
 void BitSet::set(uint32_t fromIndex, uint32_t toIndex, bool value) {
     if (toIndex >= bitSet.size()) {
         resize(toIndex + 1);
     }
-    for (bitset_type::size_type i = fromIndex; i < toIndex; ++i) {
-        bitSet.set(i, value);
-    }
+    fastSet(fromIndex, toIndex, value);
 }
 
 void BitSet::fastSet(uint32_t fromIndex, uint32_t toIndex, bool value) {
+#if BOOST_VERSION >= 106900
+    bitSet.set(fromIndex, toIndex - fromIndex, value);
+#else
     for (bitset_type::size_type i = fromIndex; i < toIndex; ++i) {
         bitSet.set(i, value);
     }
+#endif
 }
 
 void BitSet::flip(uint32_t bitIndex) {
@@ -120,15 +119,17 @@ void BitSet::flip(uint32_t fromIndex, uint32_t toIndex) {
     if (toIndex >= bitSet.size()) {
         resize(toIndex + 1);
     }
-    for (bitset_type::size_type i = fromIndex; i < toIndex; ++i) {
-        bitSet.flip(i);
-    }
+    fastFlip(fromIndex, toIndex);
 }
 
 void BitSet::fastFlip(uint32_t fromIndex, uint32_t toIndex) {
+#if BOOST_VERSION >= 106900
+    bitSet.flip(fromIndex, toIndex - fromIndex);
+#else
     for (bitset_type::size_type i = fromIndex; i < toIndex; ++i) {
         bitSet.flip(i);
     }
+#endif
 }
 
 uint32_t BitSet::size() const {
@@ -152,28 +153,21 @@ bool BitSet::fastGet(uint32_t bitIndex) const {
 }
 
 int32_t BitSet::nextSetBit(uint32_t fromIndex) const {
+#if BOOST_VERSION >= 108800
+    return bitSet.find_first(fromIndex);
+#else
     bitset_type::size_type next = fromIndex == 0 ? bitSet.find_first() : bitSet.find_next(fromIndex - 1);
     return next == bitset_type::npos ? -1 : next;
+#endif
 }
 
 void BitSet::_and(const BitSetPtr& set) {
-#if BOOST_VERSION >= 108900
     bitset_type other = set->bitSet;
     other.resize(bitSet.size());
     bitSet &= other;
-#else
-    bitset_type::size_type minBlocks = std::min(bitSet.num_blocks(), set->bitSet.num_blocks());
-    for (bitset_type::size_type i = 0; i < minBlocks; ++i) {
-        bitSet.m_bits[i] &= set->bitSet.m_bits[i];
-    }
-    if (bitSet.num_blocks() > minBlocks) {
-        std::fill(bitSet.m_bits.begin() + minBlocks, bitSet.m_bits.end(), bitset_type::block_type(0));
-    }
-#endif
 }
 
 void BitSet::_or(const BitSetPtr& set) {
-#if BOOST_VERSION >= 108900
     if (set->bitSet.size() > bitSet.size()) {
         resize(set->bitSet.size());
         bitSet |= set->bitSet;
@@ -182,22 +176,9 @@ void BitSet::_or(const BitSetPtr& set) {
         other.resize(bitSet.size());
         bitSet |= other;
     }
-#else
-    bitset_type::size_type minBlocks = std::min(bitSet.num_blocks(), set->bitSet.num_blocks());
-    if (set->bitSet.size() > bitSet.size()) {
-        resize(set->bitSet.size());
-    }
-    for (bitset_type::size_type i = 0; i < minBlocks; ++i) {
-        bitSet.m_bits[i] |= set->bitSet.m_bits[i];
-    }
-    if (bitSet.num_blocks() > minBlocks) {
-        std::copy(set->bitSet.m_bits.begin() + minBlocks, set->bitSet.m_bits.end(), bitSet.m_bits.begin() + minBlocks);
-    }
-#endif
 }
 
 void BitSet::_xor(const BitSetPtr& set) {
-#if BOOST_VERSION >= 108900
     if (set->bitSet.size() > bitSet.size()) {
         resize(set->bitSet.size());
         bitSet ^= set->bitSet;
@@ -206,31 +187,12 @@ void BitSet::_xor(const BitSetPtr& set) {
         other.resize(bitSet.size());
         bitSet ^= other;
     }
-#else
-    bitset_type::size_type minBlocks = std::min(bitSet.num_blocks(), set->bitSet.num_blocks());
-    if (set->bitSet.size() > bitSet.size()) {
-        resize(set->bitSet.size());
-    }
-    for (bitset_type::size_type i = 0; i < minBlocks; ++i) {
-        bitSet.m_bits[i] ^= set->bitSet.m_bits[i];
-    }
-    if (bitSet.num_blocks() > minBlocks) {
-        std::copy(set->bitSet.m_bits.begin() + minBlocks, set->bitSet.m_bits.end(), bitSet.m_bits.begin() + minBlocks);
-    }
-#endif
 }
 
 void BitSet::andNot(const BitSetPtr& set) {
-#if BOOST_VERSION >= 108900
     bitset_type other = set->bitSet;
     other.resize(bitSet.size());
     bitSet &= other.flip();
-#else
-    bitset_type::size_type minBlocks = std::min(bitSet.num_blocks(), set->bitSet.num_blocks());
-    for (bitset_type::size_type i = 0; i < minBlocks; ++i) {
-        bitSet.m_bits[i] &= ~set->bitSet.m_bits[i];
-    }
-#endif
 }
 
 bool BitSet::intersectsBitSet(const BitSetPtr& set) const {
@@ -238,28 +200,11 @@ bool BitSet::intersectsBitSet(const BitSetPtr& set) const {
 }
 
 uint32_t BitSet::cardinality() {
-#if BOOST_VERSION >= 108900
     return bitSet.count();
-#else
-    return bitSet.num_blocks() == 0 ? 0 : (uint32_t)BitUtil::pop_array((int64_t*)getBits(), 0, bitSet.num_blocks());
-#endif
 }
 
 void BitSet::resize(uint32_t size) {
-#if BOOST_VERSION >= 108900
     bitSet.resize(size);
-#else
-    bitset_type::size_type old_num_blocks = bitSet.num_blocks();
-    bitset_type::size_type required_blocks = bitSet.calc_num_blocks(size);
-    if (required_blocks != old_num_blocks) {
-        bitSet.m_bits.resize(required_blocks, bitset_type::block_type(0));
-    }
-    bitSet.m_num_bits = size;
-    uint64_t extra_bits = static_cast<uint64_t>(bitSet.size() % bitSet.bits_per_block);
-    if (extra_bits != 0) {
-        bitSet.m_bits.back() &= ~(~static_cast<bitset_type::block_type>(0) << extra_bits);
-    }
-#endif
 }
 
 bool BitSet::equals(const LuceneObjectPtr& other) {
@@ -272,7 +217,6 @@ bool BitSet::equals(const LuceneObjectPtr& other) {
     }
     BitSetPtr first = bitSet.num_blocks() < otherBitSet->bitSet.num_blocks() ? otherBitSet : shared_from_this();
     BitSetPtr second = bitSet.num_blocks() < otherBitSet->bitSet.num_blocks() ? shared_from_this() : otherBitSet;
-#if BOOST_VERSION >= 108900
     bitset_type::size_type f = first->bitSet.find_first();
     bitset_type::size_type s = second->bitSet.find_first();
     while (f == s) {
@@ -283,42 +227,18 @@ bool BitSet::equals(const LuceneObjectPtr& other) {
         s = second->bitSet.find_next(s);
     }
     return false;
-#else
-    bitset_type::size_type firstLength = first->bitSet.num_blocks();
-    bitset_type::size_type secondLength = second->bitSet.num_blocks();
-    for (bitset_type::size_type i = secondLength; i < firstLength; ++i) {
-        if (first->bitSet.m_bits[i] != 0) {
-            return false;
-        }
-    }
-    for (bitset_type::size_type i = 0; i < secondLength; ++i) {
-        if (first->bitSet.m_bits[i] != second->bitSet.m_bits[i]) {
-            return false;
-        }
-    }
-    return true;
-#endif
 }
 
 int32_t BitSet::hashCode() {
     // Start with a zero hash and use a mix that results in zero if the input is zero.
     // This effectively truncates trailing zeros without an explicit check.
     int64_t hash = 0;
-#if BOOST_VERSION >= 108900
     to_block_range(bitSet, boost::make_function_output_iterator(
         [&hash](bitset_type::block_type block) {
             hash ^= block;
             hash = (hash << 1) | (hash >> 63); // rotate left
         }
     ));
-#else
-    uint32_t maxSize = bitSet.num_blocks();
-    const uint64_t* bits = getBits();
-    for (uint32_t bit = 0; bit < maxSize; ++bit) {
-        hash ^= bits[bit];
-        hash = (hash << 1) | (hash >> 63); // rotate left
-    }
-#endif
     // Fold leftmost bits into right and add a constant to prevent empty sets from
     // returning 0, which is too common.
     return (int32_t)((hash >> 32) ^ hash) + 0x98761234;