-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A little package cleanup. Moved slotbox and friends into 'tuples' mod…
…ule.
- Loading branch information
Showing
16 changed files
with
109 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::tuplebox::tuples::{SlotBox, Tuple, TupleId}; | ||
use moor_values::util::slice_ref::ByteSource; | ||
use std::hash::{Hash, Hasher}; | ||
use std::sync::Arc; | ||
|
||
pub struct TupleRef { | ||
sb: Arc<SlotBox>, | ||
pub id: TupleId, | ||
} | ||
|
||
impl PartialEq for TupleRef { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.id == other.id | ||
} | ||
} | ||
|
||
impl Eq for TupleRef {} | ||
|
||
impl Hash for TupleRef { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
let slc = self.sb.get(self.id).expect("Unable to get tuple"); | ||
slc.hash(state) | ||
} | ||
} | ||
impl TupleRef { | ||
pub fn new(sb: Arc<SlotBox>, id: TupleId) -> Self { | ||
sb.upcount(id).expect("Unable to add tuple"); | ||
Self { sb, id } | ||
} | ||
|
||
pub fn get(&self) -> Tuple { | ||
Tuple::from_tuple_id(self.sb.clone(), self.id) | ||
} | ||
} | ||
|
||
impl Drop for TupleRef { | ||
fn drop(&mut self) { | ||
self.sb.dncount(self.id).expect("Unable to dncount tuple"); | ||
} | ||
} | ||
|
||
impl Clone for TupleRef { | ||
fn clone(&self) -> Self { | ||
self.sb.upcount(self.id).expect("Unable to upcount tuple"); | ||
Self { | ||
sb: self.sb.clone(), | ||
id: self.id, | ||
} | ||
} | ||
} | ||
|
||
impl ByteSource for TupleRef { | ||
fn as_slice(&self) -> &[u8] { | ||
self.sb.get(self.id).expect("Unable to get tuple").get_ref() | ||
} | ||
|
||
fn len(&self) -> usize { | ||
self.as_slice().len() | ||
} | ||
|
||
fn touch(&self) { | ||
// noop | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters