<A extends PrimaryKey.PrimaryKey>(node: A): (self: HashRing<A>) => boolean
<A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A): booleanChecks whether the ring contains a node with the same PrimaryKey value.
When to use
Use when you need to know whether registering a node would update an existing ring member because another node already has the same primary-key identity.
Details
Membership is checked with self.nodes.has(PrimaryKey.value(node)), so
matching is by primary key, not object identity or weight.
export const const has: {
<A extends PrimaryKey.PrimaryKey>(node: A): (
self: HashRing<A>
) => boolean
<A extends PrimaryKey.PrimaryKey>(
self: HashRing<A>,
node: A
): boolean
}
Checks whether the ring contains a node with the same PrimaryKey value.
When to use
Use when you need to know whether registering a node would update an existing
ring member because another node already has the same primary-key identity.
Details
Membership is checked with self.nodes.has(PrimaryKey.value(node)), so
matching is by primary key, not object identity or weight.
has: {
<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(node: A): (self: HashRing<A>) => booleanA extends import PrimaryKeyPrimaryKey.PrimaryKey>(node: A extends PrimaryKey.PrimaryKeynode: function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(node: A): (self: HashRing<A>) => booleanA): (self: HashRing<A>(parameter) self: {
baseWeight: number;
totalWeightCache: number;
nodes: Map<string, [node: A, weight: number]>;
ring: Array<[hash: number, node: string]>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface HashRing<A extends PrimaryKey.PrimaryKey>A weighted consistent-hashing ring for assigning inputs to nodes with stable
remapping as nodes are added or removed.
When to use
Use to maintain a mutable weighted hash ring for routing keys or shards to
nodes identified by PrimaryKey.
Details
Nodes are identified by their PrimaryKey value and can be iterated from the
ring.
HashRing<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(node: A): (self: HashRing<A>) => booleanA>) => boolean
<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A): booleanA extends import PrimaryKeyPrimaryKey.PrimaryKey>(self: HashRing<A>(parameter) self: {
baseWeight: number;
totalWeightCache: number;
nodes: Map<string, [node: A, weight: number]>;
ring: Array<[hash: number, node: string]>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface HashRing<A extends PrimaryKey.PrimaryKey>A weighted consistent-hashing ring for assigning inputs to nodes with stable
remapping as nodes are added or removed.
When to use
Use to maintain a mutable weighted hash ring for routing keys or shards to
nodes identified by PrimaryKey.
Details
Nodes are identified by their PrimaryKey value and can be iterated from the
ring.
HashRing<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A): booleanA>, node: A extends PrimaryKey.PrimaryKeynode: function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A): booleanA): boolean
} = import dualdual(
2,
<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A): booleanA extends import PrimaryKeyPrimaryKey.PrimaryKey>(self: HashRing<A>(parameter) self: {
baseWeight: number;
totalWeightCache: number;
nodes: Map<string, [node: A, weight: number]>;
ring: Array<[hash: number, node: string]>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface HashRing<A extends PrimaryKey.PrimaryKey>A weighted consistent-hashing ring for assigning inputs to nodes with stable
remapping as nodes are added or removed.
When to use
Use to maintain a mutable weighted hash ring for routing keys or shards to
nodes identified by PrimaryKey.
Details
Nodes are identified by their PrimaryKey value and can be iterated from the
ring.
HashRing<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A): booleanA>, node: A extends PrimaryKey.PrimaryKeynode: function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A): booleanA): boolean => self: HashRing<A>(parameter) self: {
baseWeight: number;
totalWeightCache: number;
nodes: Map<string, [node: A, weight: number]>;
ring: Array<[hash: number, node: string]>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self.HashRing<A>.nodes: Map<string, [node: A, weight: number]>nodes.Map<string, [node: A, weight: number]>.has(key: string): booleanhas(import PrimaryKeyPrimaryKey.const value: (self: PrimaryKey) => stringExtracts the string value from a PrimaryKey.
When to use
Use to read the stable string identifier from a value that implements
PrimaryKey.
Example (Reading primary key values)
import { PrimaryKey } from "effect"
class OrderId implements PrimaryKey.PrimaryKey {
constructor(private timestamp: number, private sequence: number) {}
[PrimaryKey.symbol](): string {
return `order_${this.timestamp}_${this.sequence}`
}
}
const orderId = new OrderId(1640995200000, 1)
console.log(PrimaryKey.value(orderId)) // "order_1640995200000_1"
// Can also be used with simple string-based implementations
const simpleKey = {
[PrimaryKey.symbol]: () => "simple-key-123"
}
console.log(PrimaryKey.value(simpleKey)) // "simple-key-123"
value(node: A extends PrimaryKey.PrimaryKeynode))
)