Skip to content

Commit

Permalink
implement hash trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrtgs committed Jan 10, 2024
1 parent 537e220 commit 60afdad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "heap-array"
version = "0.1.6"
version = "0.1.7"
edition = "2021"
authors = ["NightMare-Vortex"]
description = "An Implementation of a variable length array, with its main benefit over `Vec` is taking up less space"
Expand Down
16 changes: 11 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ use alloc::{
use alloc::alloc::{Allocator, Global};
use core::slice::SliceIndex;
use core::ops::{Index, IndexMut};
use std::hash::{Hash, Hasher};

use likely_stable::{unlikely};
use crate::guard::Guard;
Expand Down Expand Up @@ -1452,6 +1453,12 @@ identical_impl! {


identical_impl! {
impl<T: {Hash}, Maybe<A>> {Hash} for HeapArray<T, Maybe<A>> {
fn hash<H: Hasher>(&self, state: &mut H) {
<[T] as Hash>::hash(self.deref(), state)
}
}

impl<T, Maybe<A>> {Deref} for HeapArray<T, Maybe<A>> {
type Target = [T];

Expand Down Expand Up @@ -1495,7 +1502,7 @@ identical_impl! {



macro_rules! impl_deref_trait {
macro_rules! impl_deref_comp_trait {
($trait_name: ident |> fn $fn_name:ident(&self, other: &Self) -> $t: ty) => {
identical_impl! {
impl<T: {$trait_name}, Maybe<A>> {$trait_name} for HeapArray<T, Maybe<A>> {
Expand All @@ -1505,10 +1512,9 @@ macro_rules! impl_deref_trait {
};
}

impl_deref_trait!(PartialEq |> fn eq(&self, other: &Self) -> bool);
impl_deref_trait!(Ord |> fn cmp(&self, other: &Self) -> Ordering);
impl_deref_trait!(PartialOrd |> fn partial_cmp(&self, other: &Self) -> Option<Ordering>);

impl_deref_comp_trait!(PartialEq |> fn eq(&self, other: &Self) -> bool);
impl_deref_comp_trait!(Ord |> fn cmp(&self, other: &Self) -> Ordering);
impl_deref_comp_trait!(PartialOrd |> fn partial_cmp(&self, other: &Self) -> Option<Ordering>);
identical_impl! {
impl<T: {Eq}, Maybe<A>> {Eq} for HeapArray<T, Maybe<A>> {}
}
Expand Down

0 comments on commit 60afdad

Please sign in to comment.