topology
-> topology_hash
This commit is contained in:
parent
116507fad8
commit
2b6b3ca547
@ -37,13 +37,13 @@ pub trait AtomicBase: 'static + Send + Sync + Clone + Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This trait combines functionality of [`Mentionable`] and [`Factory`],
|
/// This trait combines functionality of [`Mentionable`] and [`Factory`],
|
||||||
/// while limiting [`MentionableTop::points_typed`] (and corresponding [`MentionableTop::topology`])
|
/// while limiting [`MentionableTop::points_typed`] (and corresponding [`MentionableTop::topology_hash`])
|
||||||
/// to an empty sequence.
|
/// to an empty sequence.
|
||||||
///
|
///
|
||||||
/// [`Mentionable`]: crate::rcore::Mentionable
|
/// [`Mentionable`]: crate::rcore::Mentionable
|
||||||
/// [`Factory`]: crate::rcore::Factory
|
/// [`Factory`]: crate::rcore::Factory
|
||||||
/// [`MentionableTop::points_typed`]: crate::rcore::MentionableTop::points_typed
|
/// [`MentionableTop::points_typed`]: crate::rcore::MentionableTop::points_typed
|
||||||
/// [`MentionableTop::topology`]: crate::rcore::MentionableTop::topology
|
/// [`MentionableTop::topology_hash`]: crate::rcore::MentionableTop::topology_hash
|
||||||
pub trait Atomic: AtomicModeParse {
|
pub trait Atomic: AtomicModeParse {
|
||||||
/// Static equivalent of [`FactoryParse::deserialize`].
|
/// Static equivalent of [`FactoryParse::deserialize`].
|
||||||
///
|
///
|
||||||
|
@ -4,7 +4,7 @@ use super::*;
|
|||||||
pub struct Point<'a, Ctx: Context<'a>, A: MentionableBase<'a>> {
|
pub struct Point<'a, Ctx: Context<'a>, A: MentionableBase<'a>> {
|
||||||
/// Hash of the referred content.
|
/// Hash of the referred content.
|
||||||
/// Derived both from the serialised value ([`Serializable::serialize`])
|
/// Derived both from the serialised value ([`Serializable::serialize`])
|
||||||
/// and its topology ([`MentionableTop::topology`]).
|
/// and its topology ([`MentionableTop::topology_hash`]).
|
||||||
pub point: Hash,
|
pub point: Hash,
|
||||||
/// [Origin] used in [`Point::resolve`].
|
/// [Origin] used in [`Point::resolve`].
|
||||||
pub origin: Arc<dyn Origin<'a, Ctx, Mtbl = A>>,
|
pub origin: Arc<dyn Origin<'a, Ctx, Mtbl = A>>,
|
||||||
|
@ -7,7 +7,7 @@ pub trait PointsVisitor<'a, Ctx: Context<'a>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>> PointsVisitor<'a, Ctx> for Vec<u8> {
|
impl<'a, Ctx: Context<'a>> PointsVisitor<'a, Ctx> for Vec<u8> {
|
||||||
/// The only natural implementation, as used in [`MentionableTop::topology`].
|
/// The only natural implementation, as used in [`MentionableTop::topology_hash`].
|
||||||
fn visit<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {
|
fn visit<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {
|
||||||
self.extend(point.point)
|
self.extend(point.point)
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ pub struct Address {
|
|||||||
/// Trait representing the "rainbow table" behaviour.
|
/// Trait representing the "rainbow table" behaviour.
|
||||||
pub trait Resolver<'a, Ctx: Context<'a>>: 'a + Send + Sync {
|
pub trait Resolver<'a, Ctx: Context<'a>>: 'a + Send + Sync {
|
||||||
/// Successfully returned value should be the inverse of the point passed
|
/// Successfully returned value should be the inverse of the point passed
|
||||||
/// with topology header ([`MentionableTop::topology()`]) omitted.
|
/// with topology header ([`MentionableTop::topology_hash()`]) omitted.
|
||||||
fn resolve(self: Arc<Self>, address: Address) -> HashResolution<'a, Ctx>;
|
fn resolve(self: Arc<Self>, address: Address) -> HashResolution<'a, Ctx>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ pub trait MentionableTop<'a, Ctx: Context<'a>>: 'a {
|
|||||||
/// See implementation for the definition.
|
/// See implementation for the definition.
|
||||||
/// Hash of all the references' points concatenated, ordered, non-unique.
|
/// Hash of all the references' points concatenated, ordered, non-unique.
|
||||||
/// Used for walking over object trees to ensure two objects with different references don't collide.
|
/// Used for walking over object trees to ensure two objects with different references don't collide.
|
||||||
fn topology(&self) -> Hash
|
fn topology_hash(&self) -> Hash
|
||||||
where
|
where
|
||||||
Self: Mentionable<'a, Ctx>,
|
Self: Mentionable<'a, Ctx>,
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@ impl<'a, A: AtomicBase> MentionableBase<'a> for AtomicObject<A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: AtomicBase> MentionableTop<'a, Ctx> for AtomicObject<A> {
|
impl<'a, Ctx: Context<'a>, A: AtomicBase> MentionableTop<'a, Ctx> for AtomicObject<A> {
|
||||||
fn topology(&self) -> Hash {
|
fn topology_hash(&self) -> Hash {
|
||||||
Ctx::hash(b"")
|
Ctx::hash(b"")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use super::*;
|
|||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
|
||||||
fn prepare_bytes_for_hashing(mentioned: &A) -> Vec<u8> {
|
fn prepare_bytes_for_hashing(mentioned: &A) -> Vec<u8> {
|
||||||
let mut vec = mentioned.topology().to_vec();
|
let mut vec = mentioned.topology_hash().to_vec();
|
||||||
mentioned.serialize(&mut vec);
|
mentioned.serialize(&mut vec);
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ impl<Ctx, F> PointFactory<Ctx, F> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableTop<'a, Ctx> for Point<'a, Ctx, A> {
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableTop<'a, Ctx> for Point<'a, Ctx, A> {
|
||||||
fn topology(&self) -> Hash {
|
fn topology_hash(&self) -> Hash {
|
||||||
Ctx::hash(&self.point)
|
Ctx::hash(&self.point)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ impl<'a, Ctx: Context<'a>> MentionableBase<'a> for TypelessMentionable<'a, Ctx>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>> MentionableTop<'a, Ctx> for TypelessMentionable<'a, Ctx> {
|
impl<'a, Ctx: Context<'a>> MentionableTop<'a, Ctx> for TypelessMentionable<'a, Ctx> {
|
||||||
fn topology(&self) -> Hash {
|
fn topology_hash(&self) -> Hash {
|
||||||
self.t_topology
|
self.t_topology
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ impl<'a, Ctx: Context<'a>> CRegularFactory<'a, Ctx> for TypelessFactory<'a, Ctx>
|
|||||||
impl<'a, Ctx: SingularCtx<'a>> TypelessMentionable<'a, Ctx> {
|
impl<'a, Ctx: SingularCtx<'a>> TypelessMentionable<'a, Ctx> {
|
||||||
pub fn from_typed<A: Mentionable<'a, Ctx>>(mentionable: Arc<A>) -> Self {
|
pub fn from_typed<A: Mentionable<'a, Ctx>>(mentionable: Arc<A>) -> Self {
|
||||||
let factory = TypelessFactory::from_typed(mentionable.factory());
|
let factory = TypelessFactory::from_typed(mentionable.factory());
|
||||||
let topology = mentionable.topology();
|
let topology = mentionable.topology_hash();
|
||||||
let points = mentionable.points_vec();
|
let points = mentionable.points_vec();
|
||||||
TypelessMentionable {
|
TypelessMentionable {
|
||||||
t_serialize: Box::new(move |serializer| mentionable.serialize(serializer)),
|
t_serialize: Box::new(move |serializer| mentionable.serialize(serializer)),
|
||||||
@ -197,7 +197,7 @@ impl<'a, Ctx: SingularCtx<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
|
|||||||
pub trait MentionableExt<'a, Ctx: Context<'a>>: Mentionable<'a, Ctx> {
|
pub trait MentionableExt<'a, Ctx: Context<'a>>: Mentionable<'a, Ctx> {
|
||||||
/// References ([Point]s) to other objects. Typeless.
|
/// References ([Point]s) to other objects. Typeless.
|
||||||
fn points_typeless(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>);
|
fn points_typeless(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>);
|
||||||
/// [Vec] of [Point]s as used by [`MentionableTop::topology`].
|
/// [Vec] of [Point]s as used by [`MentionableTop::topology_hash`].
|
||||||
fn points_vec(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>;
|
fn points_vec(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user