@graphty/algorithms
Version:
Graph algorithms library for browser environments implemented in TypeScript
91 lines • 2.43 kB
TypeScript
/**
* Core types for the Graphty Algorithms library
*/
export type NodeId = string | number;
export interface Edge {
source: NodeId;
target: NodeId;
weight?: number;
id?: string;
data?: Record<string, unknown> | undefined;
}
export interface Node {
id: NodeId;
data?: Record<string, unknown> | undefined;
}
export interface GraphConfig {
directed: boolean;
allowSelfLoops: boolean;
allowParallelEdges: boolean;
}
export interface ShortestPathResult {
distance: number;
path: NodeId[];
predecessor: Map<NodeId, NodeId | null>;
}
export type CentralityResult = Record<string, number>;
export interface TraversalResult {
visited: Set<NodeId>;
order: NodeId[];
tree?: Map<NodeId, NodeId | null>;
}
export interface CommunityResult {
communities: NodeId[][];
modularity: number;
iterations?: number;
}
export interface ComponentResult {
components: NodeId[][];
componentMap: Map<NodeId, number>;
}
export interface MSTResult {
edges: Edge[];
totalWeight: number;
}
export interface FloydWarshallResult {
distances: Map<NodeId, Map<NodeId, number>>;
predecessors: Map<NodeId, Map<NodeId, NodeId | null>>;
hasNegativeCycle: boolean;
}
export interface TraversalOptions {
targetNode?: NodeId;
visitCallback?: (node: NodeId, level: number) => void;
}
export interface DijkstraOptions {
target?: NodeId;
/**
* Use bidirectional search optimization for point-to-point queries.
* Defaults to true for graphs with >10 nodes, false for smaller graphs.
* Set explicitly to override automatic heuristic.
*/
bidirectional?: boolean;
}
export interface BellmanFordResult {
distances: Map<NodeId, number>;
previous: Map<NodeId, NodeId | null>;
hasNegativeCycle: boolean;
negativeCycleNodes?: NodeId[];
}
export interface CentralityOptions {
normalized?: boolean;
endpoints?: boolean;
mode?: "in" | "out" | "total";
}
export interface PageRankOptions {
alpha?: number;
maxIterations?: number;
tolerance?: number;
personalization?: Map<NodeId, number>;
}
export interface LouvainOptions {
resolution?: number;
maxIterations?: number;
tolerance?: number;
useOptimized?: boolean;
}
export interface GirvanNewmanOptions {
maxCommunities?: number;
minCommunitySize?: number;
maxIterations?: number;
}
//# sourceMappingURL=index.d.ts.map