Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish basic testing; Move on to stress testing small delta #38

Merged
merged 6 commits into from
Jun 27, 2024

Conversation

ujjwal-shekhar
Copy link
Contributor

@ujjwal-shekhar ujjwal-shekhar commented Jun 18, 2024

Basic pathological tests completed to make sure that most functionality (queries and basic add/append) work. Test files for now are tree.cpp and testing.cpp. Need to test more complicated appends where the chunk might get shifted around

Summary by CodeRabbit

  • New Features

    • Introduced a custom tree data structure with node operations like adding children, checking positions, and accessing sibling nodes.
    • Added new functions for tree manipulation including add_root, get_data, set_data, and print_tree.
  • Refactor

    • Refactored tree-related code to use std::optional for data storage.
    • Renamed build target from hhds to core and adjusted source and header file inclusions.
    • Commented out old test targets and added a new test target tree_test.
  • Chores

    • Migrated Bazel dependencies management from WORKSPACE to MODULE.bazel.

- Will wrap the each of the data points in an optional.
- Make MIN_SHORT_DEL as proxy for "unfilled" short delta [can do later too]
- We can always add 1 more bit to check if the first member of chunk is occupied, rest can be checked by assigning MIN_SHORT_DEL as special for not occupied and 0 for occupied but unused pointer. [We can discuss later]
Copy link
Contributor

coderabbitai bot commented Jun 18, 2024

Walkthrough

The recent updates focus on enhancing a tree data structure's functionality and testability. Key developments include refined tree operations for node management, the introduction of optional data storage, migration to Bazel's Bzlmod for dependencies, and targeted adjustments to build and test configurations. Collectively, these changes aim to improve the robustness, efficiency, and maintenance of the tree data structure while also streamlining dependency management.

Changes

Files Summary
hhds/testing.cpp, hhds/tree.cpp Significant modifications to core functions and data structures, introducing operations for node management and printing.
hhds/tree.hpp Added and updated declarations to facilitate optional data storage and new tree operations.
MODULE.bazel Transitioned from WORKSPACE to MODULE.bazel for dependency management using Bazel's Bzlmod.
hhds/BUILD Renamed targets, updated source and header globs, and adjusted test targets to include tree_test.
hhds/tests/tree_test.cpp Replaced and restructured includes, modified test classes and functions to align with tree changes.

Poem

In the land of code where tree roots lie,
Nodes now grow as the branches sigh,
Optional leaves with data bright,
Siblings dance in compiled light.
Bazel builds with a brand new song,
Testing trees, where they belong.
🌳🔧✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
hhds/tree.hpp (1)

Line range hint 13-56: The tree class in tree.hpp is well-structured with comprehensive methods for tree manipulation. However, consider optimizing the handling of sibling navigation to reduce potential performance bottlenecks, especially in large trees.

-    // Current implementation
+    // Proposed optimized implementation

Also applies to: 57-791

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ee8b6fb and a641ba8.

Files selected for processing (3)
  • hhds/testing.cpp (1 hunks)
  • hhds/tree.cpp (1 hunks)
  • hhds/tree.hpp (15 hunks)
Additional comments not posted (2)
hhds/tree.cpp (1)

4-50: The main function effectively demonstrates various tree operations. Ensure the output statements are clear and consistent for better readability.

hhds/testing.cpp (1)

6-79: The main function in testing.cpp is structured to test tree operations under more extensive conditions, including loops for adding multiple children. Consider adding more detailed error messages in the exception handling to aid debugging.

- Note: I have commented out the compilation of `*graph*.{h/c}cpp` since the files seem to be incomplete.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a641ba8 and 01d7223.

Files ignored due to path filters (1)
  • MODULE.bazel.lock is excluded by !**/*.lock
Files selected for processing (5)
  • MODULE.bazel (1 hunks)
  • hhds/BUILD (2 hunks)
  • hhds/lhtree.hpp (1 hunks)
  • hhds/tests/tree_test.cpp (1 hunks)
  • hhds/tree.cpp (1 hunks)
Files not summarized due to errors (1)
  • hhds/lhtree.hpp: Error: Message exceeds token limit
Files skipped from review due to trivial changes (1)
  • MODULE.bazel
Additional comments not posted (4)
hhds/tests/tree_test.cpp (2)

7-9: Simplify the main function.

The main function is currently a stub and returns 0. This is typical for a placeholder or a test setup file. Ensure that this function is either properly implemented or marked clearly as a placeholder if further development is intended.


1-5: Review the necessity and correctness of include statements.

The file includes several headers which seem necessary for the operations described in the PR summary. However, ensure that all included files (benchmark.h, tree.hpp, lhtree.hpp) are used in the test implementations that are planned or exist in other parts of the test suite.

hhds/BUILD (1)

Line range hint 20-92: Review changes to the BUILD file.

The modifications in the BUILD file, including the renaming of targets and the adjustment of dependencies, are aligned with the changes described in the PR. However, ensure that all dependencies listed are necessary and correctly scoped to the targets they support.

hhds/lhtree.hpp (1)

285-324: Review of the Tree_index class

The implementation of the Tree_index class appears robust and well-structured. The use of constexpr for constructors and methods ensures that these operations can be evaluated at compile time when possible, which is beneficial for performance.

However, the use of the packed attribute (line 285) should be justified as it can affect performance due to misaligned accesses, especially on architectures where alignment is crucial.

hhds/tree.cpp Outdated Show resolved Hide resolved
Comment on lines +1060 to +1230
Tree_index tree<X>::insert_next_sibling(const Tree_index &sibling, const X &data) {
I(sibling.level > 0); // No siblings to root

auto parent = get_parent(sibling);
auto *parent_lc_pos = ref_last_child_pos(parent);

GI(get_first_child(parent).pos != -1, get_parent(get_first_child(parent)).pos == parent.pos);

Tree_index child(sibling.level, -1);

if (has_next_sibling_space(sibling)) {
I((sibling.pos & 3) != 3); // sibling can not be the last if there is space
I(is_last_next_sibling_chunk(sibling));

make_space_after(sibling);

auto last_child_pos = increase_size(sibling);
I(data_stack[sibling.level].size() > sibling.pos);

child.pos = sibling.pos + 1;

set_data(child, data);
I(is_leaf(child));
if (*parent_lc_pos >> 2 == sibling.pos >> 2) { // new child is the youngest now
*parent_lc_pos = last_child_pos;
}

} else {
// WARNING: can not get ref, because the create can increse size and pointer is bogus
auto npos = get_next_sibling_pos(sibling);

if ((npos >> 2) != 0) {
Tree_index next_bucket_child(sibling.level, (npos >> 2) << 2);
I(pointers_stack[sibling.level][sibling.pos >> 2].parent == pointers_stack[sibling.level][next_bucket_child.pos >> 2].parent);
if (has_next_sibling_space(next_bucket_child)) { // No need to re-alloc.

if ((sibling.pos & 3) == 3) { // insert next bucket
make_space_after(next_bucket_child, false);
child.pos = next_bucket_child.pos;
} else {
make_space_after(sibling, next_bucket_child);
child.pos = sibling.pos + 1;
}
auto last_child_pos = increase_size(next_bucket_child);
set_data(child, data);
I(is_leaf(child));

if ((*parent_lc_pos) >> 2 == next_bucket_child.pos >> 2) {
*parent_lc_pos = last_child_pos;
}

return child;
}
}

Tree_index created_next_sibling(sibling.level, -1);

if ((sibling.pos & 3) == 3) { // last sibling in bucket
created_next_sibling.pos = create_space(parent, data);

child.pos = created_next_sibling.pos;
} else {
created_next_sibling.pos = create_space(parent, data_stack[sibling.level][sibling.pos | 3]);
auto &l = pointers_stack[created_next_sibling.level];
l[created_next_sibling.pos >> 2].first_child[0] = l[sibling.pos >> 2].first_child[3];
l[created_next_sibling.pos >> 2].last_child[0] = l[sibling.pos >> 2].last_child[3];
auto fc = l[sibling.pos >> 2].first_child[3];
if (fc != -1) {
adjust_parent_pointer(Tree_index(sibling.level + 1, fc), sibling.pos | 3, created_next_sibling.pos);
}

make_space_after(sibling);

child.pos = sibling.pos + 1;

set_data(child, data);
I(is_leaf(child));
}
I(pointers_stack[sibling.level][sibling.pos >> 2].parent
== pointers_stack[sibling.level][created_next_sibling.pos >> 2].parent);

// insert created in the next chain (if last *next_sibling>>2 is zero)
auto *next_sibling = ref_next_sibling_pos(sibling);
I(((*next_sibling) & 3) == 0);
auto *next_next_sibling = ref_next_sibling_pos(created_next_sibling);
*next_next_sibling |= *next_sibling;
*next_sibling = created_next_sibling.pos;

if ((*parent_lc_pos) >> 2 == sibling.pos >> 2) { // new child is the youngest now
*parent_lc_pos = created_next_sibling.pos;
}

I(!is_leaf(parent)); // Add sibling, so already has child
}

I(!child.is_invalid());
I(is_leaf(child));

return child;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of tree manipulation methods

The tree manipulation methods (lines 1060-1230) are crucial for the functionality of the tree data structure. The methods such as add_child, append_sibling, and insert_next_sibling are implemented with careful attention to detail.

However, there are potential improvements:

  • The methods frequently check conditions and throw exceptions using I(...). While this is useful for debugging, it might be beneficial to provide more descriptive error messages or handle errors in a way that is more informative to the users of the library.
  • The insert_next_sibling method (lines 1131-1230) is quite complex and could benefit from further comments or refactoring to improve readability and maintainability.

Consider refactoring complex methods like insert_next_sibling to break them into smaller, more manageable functions. Additionally, improve error handling to provide more context-specific information.

hhds/lhtree.hpp Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 01d7223 and 83859b3.

Files selected for processing (1)
  • hhds/tests/tree_test.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • hhds/tests/tree_test.cpp

@renau renau merged commit 027a8c4 into masc-ucsc:main Jun 27, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants