Solving MAXSAT and saying a few words about it.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

53 lines
852 B

// vim: ts=4 sw=4 et
use core::hash::{Hash, Hasher};
use core::ops::{Deref, DerefMut};
// A type for manipulating how something is hashed.
pub struct HashWrapper<T, U, F>(T, F)
where
F: Fn(&T) -> U,
U: Hash;
impl<T, U, F> HashWrapper<T, U, F>
where
F: Fn(&T) -> U,
U: Hash,
{
pub fn into_innner(self) -> T {
self.0
}
}
impl<T, U, F> Hash for HashWrapper<T, U, F>
where
F: Fn(&T) -> U,
U: Hash,
{
fn hash<H: Hasher>(&self, state: &mut H) {
self.1(&self.0).hash(state);
}
}
impl<T, U, F> Deref for HashWrapper<T, U, F>
where
F: Fn(&T) -> U,
U: Hash,
{
type Target = T;
fn deref(&self) -> &T {
&self.0
}
}
impl<T, U, F> DerefMut for HashWrapper<T, U, F>
where
F: Fn(&T) -> U,
U: Hash,
{
fn deref_mut(&mut self) -> &mut T {
&mut self.0
}
}