feat: implement pvector<T> persistent vector with O(log n) access via AVL order-statistic tree (Issue #186)#187
Conversation
Adding .gitkeep for PR creation (default mode). This file will be removed when the task is complete. Issue: netkeep80#186
…80#186) Add pvector<T, ManagerT> - a persistent sequential container that stores elements in PAP blocks linked via TreeNode fields to form a doubly-linked list with O(1) push_back operations. Key features: - O(1) push_back(), front(), back(), pop_back() with tail pointer - O(n) at(i) access via linear traversal from head - Iterator support for range-based for loops - clear() method to remove all elements and free memory - Nodes are NOT permanently locked (can be freed) Includes: - include/pmm/pvector.h - implementation - Mgr::pvector<T> type alias in PersistMemoryManager - Comprehensive test suite (test_issue186_pvector.cpp) - Documentation in README.md and docs/api_reference.md - Updated single-header generation script Fixes netkeep80#186 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Updated pmm.h and pmm_no_comments.h to include the new pvector<T> persistent vector container. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This reverts commit 570c56f.
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
✅ Ready to mergeThis pull request is now ready to be merged:
Monitored by hive-mind with --auto-restart-until-mergeable flag |
|
Используй встроенные avl-деревья в менеджер ПАП, что бы ускорить доступ к произвольному элементу вектора с O(n) до O(log n) |
|
🤖 AI Work Session Started Starting automated work session at 2026-03-12T09:43:42.553Z The PR has been converted to draft mode while work is in progress. This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback. |
…tic tree Use the built-in AVL tree in the PAP manager to index pvector elements by position, achieving O(log n) random access as requested in the issue feedback. Implementation changes: - Replace linked-list structure with an AVL order-statistic tree. - The `weight` field of each TreeNode stores the total subtree size (self + all descendants), enabling O(log n) index-based lookup (_avl_find_by_index). - Custom _rotate_left/_rotate_right and _rebalance_up maintain both `height` (for AVL balance) and `weight` (for subtree sizes) on every structural change. - push_back inserts as rightmost node in O(log n). - pop_back removes the rightmost node in O(log n). - size() is now O(1) (reads weight of root). - front()/back() are O(log n) leftmost/rightmost traversals. - Iterator uses in-order (left→node→right) traversal, preserving order. - Added test I186-N to verify AVL invariants: correct weight fields, |bf|<=1 at every node, and tree height bounded by O(log n). Fixes netkeep80#186 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nts) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
AI Work Session CompletedImplemented the requested improvement: O(log n) random access via AVL order-statistic tree. Changes madeThe pvector now uses the built-in AVL tree infrastructure of the PAP manager instead of a linked list. Key design:
New test I186-N verifies AVL invariants at every node after 100 push_back + 30 pop_back operations:
All 53 existing tests + 14 pvector tests pass. All CI checks pass. |
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
✅ Ready to mergeThis pull request is now ready to be merged:
Monitored by hive-mind with --auto-restart-until-mergeable flag |
Implements
pvector<T>— a persistent sequential container (vector) for the persistent address space (PAP) as requested in Issue #186.Key features
at(i)— uses an AVL order-statistic tree indexed by element position.weightof root node (total subtree size).Implementation
Each element is stored in a separate PAP block. The built-in
TreeNodefields are used for the AVL tree:weight→ total subtree size (self + all descendants). Enables O(log n) position lookup.left_offset/right_offset→ left/right children (smaller/larger indices).parent_offset→ parent node.avl_height→ subtree height for AVL balance.The
_avl_find_by_index(p, i)function navigates O(log n) using subtree sizes:i < left.weight→ go lefti == left.weight→ foundi > left.weight→ go right withi -= left.weight + 1Custom
_rotate_left/_rotate_rightand_rebalance_upmaintain bothheight(AVL balance) andweight(subtree sizes) on every structural change.Changed files
include/pmm/pvector.h— New AVL order-statistic tree implementation (replaces linked-list)include/pmm/persist_memory_manager.h— AddedMgr::pvector<T>type aliastests/test_issue186_pvector.cpp— 14 test cases (added I186-N: AVL invariant verification)tests/CMakeLists.txt— Added test registrationdocs/api_reference.md— API documentationREADME.md— Updated with pvector sectionscripts/generate-single-headers.sh— Include pvector in single-header generationsingle_include/pmm/pmm.h— Regenerated single-headerchangelog.d/20260311_120000_pvector.md— Changelog fragmentTest plan
All 53 existing tests pass, plus 14 new pvector tests:
weightfields are correct at every node, balance factor |bf|≤1, and tree height is O(log n)Fixes #186