Skip to content

HashRing

9 exports Added in v3.19.0 Source

Combinators

add

Added in v3.19.0 Source

Add 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.

Signature

declare const add: {
  <A extends PrimaryKey>(
    node: A,
    options?: {
      readonly weight?: number;
    },
  ): (self: HashRing<A>) => HashRing<A>;
  <A extends PrimaryKey>(
    self: HashRing<A>,
    node: A,
    options?: {
      readonly weight?: number;
    },
  ): HashRing<A>;
};

addMany

Added in v3.19.0 Source

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

Signature

declare const addMany: {
  <A extends PrimaryKey>(
    nodes: Iterable<A>,
    options?: {
      readonly weight?: number;
    },
  ): (self: HashRing<A>) => HashRing<A>;
  <A extends PrimaryKey>(
    self: HashRing<A>,
    nodes: Iterable<A>,
    options?: {
      readonly weight?: number;
    },
  ): HashRing<A>;
};

get

Added in v3.19.0 Source

Gets the node which should handle the given input. Returns undefined if the hashring has no elements with weight.

Signature

declare function get<A extends PrimaryKey>(self: HashRing<A>, input: string): A | undefined;

getShards

Added in v3.19.0 Source

Distributes count shards across the nodes in the ring, attempting to balance the number of shards allocated to each node. Returns undefined if the hashring has no elements with weight.

Signature

declare function getShards<A extends PrimaryKey>(
  self: HashRing<A>,
  count: number,
): Array<A> | undefined;

has

Added in v3.19.0 Source

Signature

declare const has: {
  <A extends PrimaryKey>(node: A): (self: HashRing<A>) => boolean;
  <A extends PrimaryKey>(self: HashRing<A>, node: A): boolean;
};

remove

Added in v3.19.0 Source

Removes the node from the ring. No-op's if the node does not exist.

Signature

declare const remove: {
  <A extends PrimaryKey>(node: A): (self: HashRing<A>) => HashRing<A>;
  <A extends PrimaryKey>(self: HashRing<A>, node: A): HashRing<A>;
};

Constructors

make

Added in v3.19.0 Source

Signature

declare function make<A extends PrimaryKey>(options?: {
  readonly baseWeight?: number;
}): HashRing<A>;

Guards

isHashRing

Added in v3.19.0 Source

Signature

declare function isHashRing(u: unknown): u is HashRing<any>;

Models

HashRing interface

Added in v3.19.0 Source

Signature

interface HashRing<A extends PrimaryKey.PrimaryKey> extends Pipeable, "/home/runner/work/website/website/.effect-source-v3/packages/effect/src/Iterable"<A> {
  readonly "~effect/cluster/HashRing": "~effect/cluster/HashRing";
  readonly baseWeight: number;
  readonly nodes: Map<string, [node: A, weight: number]>;
  ring: Array<[hash: number, node: string]>;
  totalWeightCache: number;
}