-
Notifications
You must be signed in to change notification settings - Fork 21
/
utility-types.ts
112 lines (107 loc) · 2.8 KB
/
utility-types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// deno-lint-ignore no-explicit-any
export type Constructor<T = unknown> = new (...args: any[]) => T;
export type Bit = 0 | 1;
export interface IndexedCollection<T = number> {
length: number;
[n: number]: T;
}
export type TypedArrayConstructors =
| Constructor<Int8Array>
| Constructor<Uint8Array>
| Constructor<Uint8ClampedArray>
| Constructor<Int16Array>
| Constructor<Uint16Array>
| Constructor<Int32Array>
| Constructor<Uint32Array>
| Constructor<Float32Array>
| Constructor<Float64Array>;
export interface AdjacencyStructure extends IndexedCollection {
empty: unknown;
/**
* The number of vertices.
*/
vertices: number;
/**
* The maximum number of edges.
*/
edges: number;
/**
* Adds an edge between two vertices.
*
* @param x the starting vertex
* @param y the ending vertex
* @param weight the weight
* @return the structure
*/
addEdge(x: number, y: number, weight?: number): this;
/**
* Returns the weight of the edge between given vertices
* or NaN if the edge doesn't exist.
*
* @param x the starting vertex
* @param y the ending vertex
* @returns the edge
*/
getEdge(x: number, y: number): number;
/**
* Checks if there is an edge between two vertices.
*
* @param x the starting vertex
* @param y the ending vertex
*/
hasEdge(x: number, y: number): boolean;
/**
* Iterates over incoming edges of a vertex.
*
* @param vertex the vertex
*/
inEdges(x: number): Generator<number, void, unknown>;
/**
* Check if all available edges are set.
*/
isFull(): boolean;
/**
* Iterates over outgoing edges of a vertex.
*
* @param vertex the vertex
*/
outEdges(x: number): Generator<number, void, unknown>;
/**
* Removes an edge between two vertices.
*
* @param x the starting vertex
* @param y the ending vertex
* @return the structure
*/
removeEdge(x: number, y: number): this;
}
export type AdjacencyStructureConstructor<
U extends TypedArrayConstructors,
> = {
directed: boolean;
weighted: boolean;
get [Symbol.species](): U;
// deno-lint-ignore no-explicit-any
new (...args: any[]): AdjacencyStructure;
/**
* Create an adjacency structure of specified dimensions.
*
* @param vertices the number of vertices
* @param edges the maximum amount of edges
* @return a new adjacency structure of specified dimentions
*/
create<T extends AdjacencyStructureConstructor<U>>(
this: T,
vertices: number,
edges?: number,
): InstanceType<T>;
/**
* Returns the length of underlying TypedArray required to hold a structure
* of the specified dimensions.
*
* @param vertices the number of vertices
* @param edges the maximum amount of edges
* @return the length
*/
getLength(vertices: number, edges?: number): number;
} & U;