Files
orchid/orchid-api/src/interner.rs

92 lines
2.5 KiB
Rust

use std::num::NonZeroU64;
use orchid_api_derive::{Coding, Hierarchy};
use orchid_api_traits::Request;
use crate::{ExtHostNotif, ExtHostReq, HostExtReq};
/// Intern requests sent by the replica to the master. These requests are
/// repeatable.
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(ExtHostReq)]
#[extendable]
pub enum IntReq {
InternStr(InternStr),
InternStrv(InternStrv),
ExternStr(ExternStr),
ExternStrv(ExternStrv),
}
/// replica -> master to intern a string on the master. Repeatable.
///
/// See [IntReq]
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
#[extends(IntReq, ExtHostReq)]
pub struct InternStr(pub String);
impl Request for InternStr {
type Response = TStr;
}
/// replica -> master to find the interned string corresponding to a key.
///
/// Repeatable.
///
/// See [IntReq]
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(IntReq, ExtHostReq)]
pub struct ExternStr(pub TStr);
impl Request for ExternStr {
type Response = String;
}
/// replica -> master to intern a vector of interned strings
///
/// Repeatable.
///
/// See [IntReq]
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(IntReq, ExtHostReq)]
pub struct InternStrv(pub Vec<TStr>);
impl Request for InternStrv {
type Response = TStrv;
}
/// replica -> master to find the vector of interned strings corresponding to a
/// token
///
/// Repeatable.
///
/// See [IntReq]
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(IntReq, ExtHostReq)]
pub struct ExternStrv(pub TStrv);
impl Request for ExternStrv {
type Response = Vec<TStr>;
}
/// A substitute for an interned string in serialized datastructures.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Coding)]
pub struct TStr(pub NonZeroU64);
/// A substitute for an interned string sequence in serialized datastructures.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Coding)]
pub struct TStrv(pub NonZeroU64);
/// A request to sweep the replica. The master will not be sweeped until all
/// replicas respond. For efficiency, replicas should make sure to send the
/// [Sweeped] notif before returning.
#[derive(Clone, Copy, Debug, Coding, Hierarchy)]
#[extends(HostExtReq)]
pub struct Sweep;
impl Request for Sweep {
type Response = ();
}
/// List of keys in this replica that were removed during a sweep. This may have
/// been initiated via a [Sweep] request, but can also be triggered by the
/// replica autonomously.
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(ExtHostNotif)]
pub struct Sweeped {
pub strings: Vec<TStr>,
pub vecs: Vec<TStrv>,
}