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

add generic heap implementation #4

Closed
wants to merge 11 commits into from

Conversation

fabioibanez
Copy link

PR to add a generic heap data structure that fits into fixed buffers.

Tried to make the tests comparable to data structures implemented with NodeAllocator.

src/heap.rs Outdated Show resolved Hide resolved
src/heap.rs Outdated Show resolved Hide resolved
src/heap.rs Outdated Show resolved Hide resolved
src/heap.rs Outdated Show resolved Hide resolved
src/heap.rs Outdated Show resolved Hide resolved
src/heap.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/heap.rs Outdated Show resolved Hide resolved
#[derive(Debug, Default, Clone, PartialOrd, PartialEq)]
pub struct Node<K, V> {
pub key: K,
pub value: V,
Copy link
Author

Choose a reason for hiding this comment

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

Fixed node struct to include V for arbitrary metadata

}
}

fn _heapifydown(&mut self, index: usize) {
Copy link
Author

Choose a reason for hiding this comment

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

iterative implementation of all previously recursive functions ✅

}

#[derive(Debug)]
pub struct BinaryHeapIterator<
Copy link
Author

Choose a reason for hiding this comment

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

Implemented iterator

@jarry-xiao
Copy link
Collaborator

Please remove the .DS_Store file from the PR

@jarry-xiao
Copy link
Collaborator

Why are there so many changes in the other files?

}
})
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you paste the benchmark stats?

Copy link
Author

Choose a reason for hiding this comment

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

test bench_tests::bench_sokoban_binary_heap_insert_1000_u128 ... bench: 44,853 ns/iter (+/- 617)
test bench_tests::bench_sokoban_binary_heap_insert_20000_u128 ... bench: 45,293 ns/iter (+/- 1,492)
test bench_tests::bench_sokoban_binary_heap_remove_1000_u128 ... bench: 91,893 ns/iter (+/- 415)

test bench_tests::bench_std_binary_heap_insert_1000_u128 ... bench: 42,571 ns/iter (+/- 1,718)
test bench_tests::bench_std_binary_heap_insert_20000_u128 ... bench: 846,477 ns/iter (+/- 43,306)
test bench_tests::bench_std_binary_heap_remove_1000_u128 ... bench: 70,234 ns/iter (+/- 3,002)

src/binary_heap.rs Outdated Show resolved Hide resolved
src/binary_heap.rs Outdated Show resolved Hide resolved
src/binary_heap.rs Outdated Show resolved Hide resolved
self.size += 1;
}

pub fn _pop_min(&mut self) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this index is guaranteed to be the "min"

tests/test.rs Outdated Show resolved Hide resolved
@jarry-xiao jarry-xiao closed this Sep 13, 2022
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.

None yet

2 participants