Skip to content

[Refactor] Extract total_count to InnerIndexInterface base class #1681

@LHT129

Description

@LHT129

Description

Extract the total_count_ member variable from individual index implementations (HGraph, BruteForce) to the common InnerIndexInterface base class for unified management.

Background

Currently, total_count_ is defined separately in each index class:

  • HGraph: std::atomic<uint64_t> total_count_{0}
  • BruteForce: uint64_t total_count_{0}

This leads to code duplication and inconsistent management. By extracting to the base class, we can:

  • Reduce code duplication
  • Provide consistent interface for accessing total count
  • Improve maintainability

Requirements

  • Add GetTotalCount() method to InnerIndexInterface
  • Add std::atomic<uint64_t> total_count_ member to InnerIndexInterface
  • Remove total_count_ from HGraph and BruteForce
  • Update BruteForce to use atomic operations for thread safety
  • All tests pass

Technical Details

  • Use std::atomic<uint64_t> to ensure thread safety
  • BruteForce operations converted to atomic operations:
    • total_count_++++total_count_
    • total_count_----total_count_
    • Direct assignment → total_count_.store()
    • Read access → total_count_.load()

Acceptance Criteria

  • Code compiles successfully
  • Unit tests pass (77666006 assertions in 290 test cases)
  • Functional tests pass (80/81 passed)
  • Lint check passes
  • No performance regression

Related

  • Original task file: /home/tianlan.lht/code/workspace/total_count.md
  • Branch: lht/total_count
  • Commit: 5cd6acb

Notes

  • IVF uses total_elements_ with different semantics
  • Pyramid uses cur_element_count_ with different semantics
  • Only HGraph and BruteForce have consistent usage patterns for extraction

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions