@@ -243,7 +243,9 @@ class FieldIndex {
243
243
static util::ComparisonResult SemanticCompare (const FieldIndex& left,
244
244
const FieldIndex& right);
245
245
246
- FieldIndex () : index_id_(UnknownId()) {
246
+ FieldIndex ()
247
+ : index_id_(UnknownId()),
248
+ unique_id_ (ref_count_.fetch_add(1 , std::memory_order_acq_rel)) {
247
249
}
248
250
249
251
FieldIndex (int32_t index_id,
@@ -253,7 +255,50 @@ class FieldIndex {
253
255
: index_id_(index_id),
254
256
collection_group_(std::move(collection_group)),
255
257
segments_(std::move(segments)),
256
- state_(std::move(state)) {
258
+ state_(std::move(state)),
259
+ unique_id_(ref_count_.fetch_add(1 , std::memory_order_acq_rel)) {
260
+ }
261
+
262
+ // Copy constructor
263
+ FieldIndex (const FieldIndex& other)
264
+ : index_id_(other.index_id_),
265
+ collection_group_(other.collection_group_),
266
+ segments_(other.segments_),
267
+ state_(other.state_),
268
+ unique_id_(ref_count_.fetch_add(1 , std::memory_order_acq_rel)) {
269
+ }
270
+
271
+ // Copy assignment operator
272
+ FieldIndex& operator =(const FieldIndex& other) {
273
+ if (this != &other) {
274
+ index_id_ = other.index_id_ ;
275
+ collection_group_ = other.collection_group_ ;
276
+ segments_ = other.segments_ ;
277
+ state_ = other.state_ ;
278
+ unique_id_ = ref_count_.fetch_add (1 , std::memory_order_acq_rel);
279
+ }
280
+ return *this ;
281
+ }
282
+
283
+ // Move constructor
284
+ FieldIndex (FieldIndex&& other) noexcept
285
+ : index_id_(other.index_id_),
286
+ collection_group_ (std::move(other.collection_group_)),
287
+ segments_(std::move(other.segments_)),
288
+ state_(std::move(other.state_)),
289
+ unique_id_(ref_count_.fetch_add(1 , std::memory_order_acq_rel)) {
290
+ }
291
+
292
+ // Move assignment operator
293
+ FieldIndex& operator =(FieldIndex&& other) noexcept {
294
+ if (this != &other) {
295
+ index_id_ = other.index_id_ ;
296
+ collection_group_ = std::move (other.collection_group_ );
297
+ segments_ = std::move (other.segments_ );
298
+ state_ = std::move (other.state_ );
299
+ unique_id_ = ref_count_.fetch_add (1 , std::memory_order_acq_rel);
300
+ }
301
+ return *this ;
257
302
}
258
303
259
304
/* *
@@ -285,6 +330,14 @@ class FieldIndex {
285
330
/* * Returns the ArrayContains/ArrayContainsAny segment for this index. */
286
331
absl::optional<Segment> GetArraySegment () const ;
287
332
333
+ /* *
334
+ * Returns the unique identifier for this object, ensuring a strict ordering
335
+ * in the priority queue's comparison function.
336
+ */
337
+ int unique_id () const {
338
+ return unique_id_;
339
+ }
340
+
288
341
/* *
289
342
* A type that can be used as the "Compare" template parameter of ordered
290
343
* collections to have the elements ordered using
@@ -308,6 +361,10 @@ class FieldIndex {
308
361
std::string collection_group_;
309
362
std::vector<Segment> segments_;
310
363
IndexState state_;
364
+ int unique_id_;
365
+
366
+ // TODO(C++17): Replace with inline static std::atomic<int> ref_count_ = 0;
367
+ static std::atomic<int > ref_count_;
311
368
};
312
369
313
370
inline bool operator ==(const FieldIndex& lhs, const FieldIndex& rhs) {
0 commit comments