Hyperlinkv0.8.0-beta.28

HashRing

HashRing.addconsteffect/HashRing.ts:206
<A extends PrimaryKey.PrimaryKey>(
  node: A,
  options?: { readonly weight?: number | undefined }
): (self: HashRing<A>) => HashRing<A>
<A extends PrimaryKey.PrimaryKey>(
  self: HashRing<A>,
  node: A,
  options?: { readonly weight?: number | undefined }
): HashRing<A>

Adds a new node to the ring. If the node already exists in the ring, it will be updated. For example, you can use this to update the node's weight.

When to use

Use to register one node in a HashRing so lookups and shard assignments can return it, or update that node's weight.

Details

Nodes are matched by PrimaryKey.value. The weight defaults to 1 and is clamped to at least 0.1.

Gotchas

This mutates and returns the same ring instance.

combinatorsaddManyremovehas
Source effect/HashRing.ts:20610 lines
export const add: {
  <A extends PrimaryKey.PrimaryKey>(node: A, options?: {
    readonly weight?: number | undefined
  }): (self: HashRing<A>) => HashRing<A>
  <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A, options?: {
    readonly weight?: number | undefined
  }): HashRing<A>
} = dual((args) => isHashRing(args[0]), <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A, options?: {
  readonly weight?: number | undefined
}): HashRing<A> => addMany(self, [node], options))