@obinexusmk2/hypernum 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +355 -256
  3. package/dist/index.cjs +4 -8
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +4 -7
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.umd.js +2 -2
  9. package/dist/index.umd.js.map +1 -1
  10. package/dist/types/{config → src/config}/config-loader.d.ts +0 -0
  11. package/dist/types/src/config/config-loader.d.ts.map +1 -0
  12. package/dist/types/{config → src/config}/config-parser.d.ts +0 -0
  13. package/dist/types/src/config/config-parser.d.ts.map +1 -0
  14. package/dist/types/{config → src/config}/config-resolver.d.ts +0 -0
  15. package/dist/types/src/config/config-resolver.d.ts.map +1 -0
  16. package/dist/types/{config → src/config}/config-source.d.ts +0 -0
  17. package/dist/types/src/config/config-source.d.ts.map +1 -0
  18. package/dist/types/{config → src/config}/index.d.ts +0 -0
  19. package/dist/types/src/config/index.d.ts.map +1 -0
  20. package/dist/types/{core → src/core}/common.d.ts +0 -0
  21. package/dist/types/src/core/common.d.ts.map +1 -0
  22. package/dist/types/{core → src/core}/config.d.ts +0 -0
  23. package/dist/types/src/core/config.d.ts.map +1 -0
  24. package/dist/types/{core → src/core}/constants.d.ts +0 -0
  25. package/dist/types/src/core/constants.d.ts.map +1 -0
  26. package/dist/types/{core → src/core}/errors.d.ts +0 -0
  27. package/dist/types/src/core/errors.d.ts.map +1 -0
  28. package/dist/types/{core → src/core}/hypernum.d.ts +0 -0
  29. package/dist/types/src/core/hypernum.d.ts.map +1 -0
  30. package/dist/types/{core → src/core}/index.d.ts +0 -0
  31. package/dist/types/src/core/index.d.ts.map +1 -0
  32. package/dist/types/{index.d.ts → src/index.d.ts} +1 -1
  33. package/dist/types/src/index.d.ts.map +1 -0
  34. package/dist/types/{operations → src/operations}/arithmetic.d.ts +0 -0
  35. package/dist/types/src/operations/arithmetic.d.ts.map +1 -0
  36. package/dist/types/{operations → src/operations}/bitwise.d.ts +0 -0
  37. package/dist/types/src/operations/bitwise.d.ts.map +1 -0
  38. package/dist/types/{operations → src/operations}/comparison.d.ts +0 -0
  39. package/dist/types/src/operations/comparison.d.ts.map +1 -0
  40. package/dist/types/{operations → src/operations}/conversion.d.ts +0 -0
  41. package/dist/types/src/operations/conversion.d.ts.map +1 -0
  42. package/dist/types/{operations → src/operations}/factorial.d.ts +0 -0
  43. package/dist/types/src/operations/factorial.d.ts.map +1 -0
  44. package/dist/types/{operations → src/operations}/index.d.ts +0 -0
  45. package/dist/types/src/operations/index.d.ts.map +1 -0
  46. package/dist/types/{operations → src/operations}/power.d.ts +0 -0
  47. package/dist/types/src/operations/power.d.ts.map +1 -0
  48. package/dist/types/{storage → src/storage}/Heap.d.ts +0 -0
  49. package/dist/types/src/storage/Heap.d.ts.map +1 -0
  50. package/dist/types/{storage → src/storage}/index.d.ts +0 -0
  51. package/dist/types/src/storage/index.d.ts.map +1 -0
  52. package/dist/types/{structures → src/structures}/ackermann.d.ts +0 -0
  53. package/dist/types/src/structures/ackermann.d.ts.map +1 -0
  54. package/dist/types/{structures → src/structures}/big-array.d.ts +0 -0
  55. package/dist/types/src/structures/big-array.d.ts.map +1 -0
  56. package/dist/types/{structures → src/structures}/index.d.ts +0 -0
  57. package/dist/types/src/structures/index.d.ts.map +1 -0
  58. package/dist/types/{structures → src/structures}/number-tree.d.ts +0 -0
  59. package/dist/types/src/structures/number-tree.d.ts.map +1 -0
  60. package/dist/types/{structures → src/structures}/power-tower.d.ts +0 -0
  61. package/dist/types/src/structures/power-tower.d.ts.map +1 -0
  62. package/dist/types/{utils → src/utils}/formatting.d.ts +0 -0
  63. package/dist/types/src/utils/formatting.d.ts.map +1 -0
  64. package/dist/types/{utils → src/utils}/index.d.ts +0 -0
  65. package/dist/types/src/utils/index.d.ts.map +1 -0
  66. package/dist/types/{utils → src/utils}/parser.d.ts +0 -0
  67. package/dist/types/src/utils/parser.d.ts.map +1 -0
  68. package/dist/types/{utils → src/utils}/precision.d.ts +0 -0
  69. package/dist/types/src/utils/precision.d.ts.map +1 -0
  70. package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
  71. package/dist/types/src/utils/validation.d.ts.map +1 -0
  72. package/package.json +169 -164
  73. package/rollup.config.js +163 -161
  74. package/src/cli/hypernum.js +272 -0
  75. package/src/config/config-loader.ts +0 -0
  76. package/src/config/config-parser.ts +160 -160
  77. package/src/config/config-resolver.ts +0 -0
  78. package/src/config/config-source.ts +0 -0
  79. package/src/config/index.ts +0 -0
  80. package/src/core/common.ts +184 -184
  81. package/src/core/config.ts +392 -392
  82. package/src/core/constants.ts +101 -101
  83. package/src/core/errors.ts +202 -202
  84. package/src/core/hypernum.ts +240 -240
  85. package/src/core/index.ts +4 -4
  86. package/src/index.ts +179 -182
  87. package/src/operations/arithmetic.ts +332 -332
  88. package/src/operations/bitwise.ts +366 -366
  89. package/src/operations/comparison.ts +271 -271
  90. package/src/operations/conversion.ts +399 -399
  91. package/src/operations/factorial.ts +278 -278
  92. package/src/operations/index.ts +4 -4
  93. package/src/operations/power.ts +315 -315
  94. package/src/storage/Heap.ts +237 -237
  95. package/src/storage/index.ts +0 -0
  96. package/src/structures/ackermann.ts +232 -232
  97. package/src/structures/big-array.ts +305 -305
  98. package/src/structures/index.ts +3 -3
  99. package/src/structures/number-tree.ts +403 -403
  100. package/src/structures/power-tower.ts +277 -277
  101. package/src/types/common.d.ts +356 -356
  102. package/src/types/core.d.ts +160 -160
  103. package/src/types/index.d.ts +1 -1
  104. package/src/utils/formatting.ts +245 -245
  105. package/src/utils/index.ts +4 -4
  106. package/src/utils/parser.ts +244 -244
  107. package/src/utils/precision.ts +216 -216
  108. package/src/utils/validation.ts +182 -182
  109. package/tsconfig.json +83 -83
  110. package/dist/types/config/config-loader.d.ts.map +0 -1
  111. package/dist/types/config/config-parser.d.ts.map +0 -1
  112. package/dist/types/config/config-resolver.d.ts.map +0 -1
  113. package/dist/types/config/config-source.d.ts.map +0 -1
  114. package/dist/types/config/index.d.ts.map +0 -1
  115. package/dist/types/core/common.d.ts.map +0 -1
  116. package/dist/types/core/config.d.ts.map +0 -1
  117. package/dist/types/core/constants.d.ts.map +0 -1
  118. package/dist/types/core/errors.d.ts.map +0 -1
  119. package/dist/types/core/hypernum.d.ts.map +0 -1
  120. package/dist/types/core/index.d.ts.map +0 -1
  121. package/dist/types/index.d.ts.map +0 -1
  122. package/dist/types/operations/arithmetic.d.ts.map +0 -1
  123. package/dist/types/operations/bitwise.d.ts.map +0 -1
  124. package/dist/types/operations/comparison.d.ts.map +0 -1
  125. package/dist/types/operations/conversion.d.ts.map +0 -1
  126. package/dist/types/operations/factorial.d.ts.map +0 -1
  127. package/dist/types/operations/index.d.ts.map +0 -1
  128. package/dist/types/operations/power.d.ts.map +0 -1
  129. package/dist/types/storage/Heap.d.ts.map +0 -1
  130. package/dist/types/storage/index.d.ts.map +0 -1
  131. package/dist/types/structures/ackermann.d.ts.map +0 -1
  132. package/dist/types/structures/big-array.d.ts.map +0 -1
  133. package/dist/types/structures/index.d.ts.map +0 -1
  134. package/dist/types/structures/number-tree.d.ts.map +0 -1
  135. package/dist/types/structures/power-tower.d.ts.map +0 -1
  136. package/dist/types/utils/formatting.d.ts.map +0 -1
  137. package/dist/types/utils/index.d.ts.map +0 -1
  138. package/dist/types/utils/parser.d.ts.map +0 -1
  139. package/dist/types/utils/precision.d.ts.map +0 -1
  140. package/dist/types/utils/validation.d.ts.map +0 -1
@@ -1,238 +1,238 @@
1
-
2
- /**
3
- * Represents the result of a comparison operation
4
- * -1: first value is less than second value
5
- * 0: values are equal
6
- * 1: first value is greater than second value
7
- */
8
- export type ComparisonResult = -1 | 0 | 1;
9
-
10
- /**
11
- * Generic comparator function type for heap elements
12
- */
13
- export type Comparator<T> = (a: T, b: T) => ComparisonResult;
14
-
15
- /**
16
- * Abstract base heap class implementing common heap operations
17
- */
18
- abstract class Heap<T> {
19
- protected heap: T[];
20
- protected readonly compare: Comparator<T>;
21
-
22
- constructor(comparator: Comparator<T>) {
23
- this.heap = [];
24
- this.compare = comparator;
25
- }
26
-
27
- /**
28
- * Gets the size of the heap
29
- */
30
- public size(): number {
31
- return this.heap.length;
32
- }
33
-
34
- /**
35
- * Checks if the heap is empty
36
- */
37
- public isEmpty(): boolean {
38
- return this.heap.length === 0;
39
- }
40
-
41
- /**
42
- * Peeks at the root element without removing it
43
- */
44
- public peek(): T | undefined {
45
- return this.heap[0];
46
- }
47
-
48
- /**
49
- * Inserts a new element into the heap
50
- */
51
- public push(value: T): void {
52
- this.heap.push(value);
53
- this.siftUp(this.heap.length - 1);
54
- }
55
-
56
- /**
57
- * Removes and returns the root element
58
- */
59
- public pop(): T | undefined {
60
- if (this.isEmpty()) {
61
- return undefined;
62
- }
63
-
64
- const root = this.heap[0];
65
- const last = this.heap.pop()!;
66
-
67
- if (!this.isEmpty()) {
68
- this.heap[0] = last;
69
- this.siftDown(0);
70
- }
71
-
72
- return root;
73
- }
74
-
75
- /**
76
- * Removes all elements from the heap
77
- */
78
- public clear(): void {
79
- this.heap = [];
80
- }
81
-
82
- /**
83
- * Creates a heap from an array of elements
84
- */
85
- public static heapify<T extends {}>(array: T[], comparator: Comparator<T>): Heap<T> {
86
- const heap = this instanceof MinHeap ? new MinHeap(comparator) : new MaxHeap(comparator);
87
- array.forEach(item => heap.push(item));
88
- return heap;
89
- }
90
-
91
- /**
92
- * Gets the parent index of a node
93
- */
94
- protected getParentIndex(index: number): number {
95
- return Math.floor((index - 1) / 2);
96
- }
97
-
98
- /**
99
- * Gets the left child index of a node
100
- */
101
- protected getLeftChildIndex(index: number): number {
102
- return 2 * index + 1;
103
- }
104
-
105
- /**
106
- * Gets the right child index of a node
107
- */
108
- protected getRightChildIndex(index: number): number {
109
- return 2 * index + 2;
110
- }
111
-
112
- /**
113
- * Swaps two elements in the heap
114
- */
115
- protected swap(i: number, j: number): void {
116
- const temp = this.heap[i]!;
117
- this.heap[i] = this.heap[j]!;
118
- this.heap[j] = temp;
119
- }
120
-
121
- /**
122
- * Moves an element up the heap until heap property is satisfied
123
- */
124
- protected abstract siftUp(index: number): void;
125
-
126
- /**
127
- * Moves an element down the heap until heap property is satisfied
128
- */
129
- protected abstract siftDown(index: number): void;
130
- }
131
-
132
- /**
133
- * MinHeap implementation where the root is the smallest element
134
- */
135
- export class MinHeap<T> extends Heap<T> {
136
- constructor(comparator: Comparator<T>) {
137
- super(comparator);
138
- }
139
-
140
- protected siftUp(index: number): void {
141
- while (index > 0) {
142
- const parentIndex = this.getParentIndex(index);
143
- if (this.compare(this.heap[index]!, this.heap[parentIndex]!) >= 0) {
144
- break;
145
- }
146
- this.swap(index, parentIndex);
147
- index = parentIndex;
148
- }
149
- }
150
-
151
- protected siftDown(index: number): void {
152
- const size = this.heap.length;
153
-
154
- while (true) {
155
- let smallest = index;
156
- const left = this.getLeftChildIndex(index);
157
- const right = this.getRightChildIndex(index);
158
-
159
- if (left < size && this.compare(this.heap[left]!, this.heap[smallest]!) < 0) {
160
- smallest = left;
161
- }
162
-
163
- if (right < size && this.heap[right] !== undefined && this.compare(this.heap[right] as T, this.heap[smallest] as T) < 0) {
164
- smallest = right;
165
- }
166
-
167
- if (smallest === index) {
168
- break;
169
- }
170
-
171
- this.swap(index, smallest);
172
- index = smallest;
173
- }
174
- }
175
- }
176
-
177
- /**
178
- * MaxHeap implementation where the root is the largest element
179
- */
180
- export class MaxHeap<T> extends Heap<T> {
181
- constructor(comparator: Comparator<T>) {
182
- super(comparator);
183
- }
184
-
185
- protected siftUp(index: number): void {
186
- while (index > 0) {
187
- const parentIndex = this.getParentIndex(index);
188
- if (this.compare(this.heap[index]!, this.heap[parentIndex]!) <= 0) {
189
- break;
190
- }
191
- this.swap(index, parentIndex);
192
- index = parentIndex;
193
- }
194
- }
195
-
196
- protected siftDown(index: number): void {
197
- const size = this.heap.length;
198
-
199
- while (true) {
200
- let largest = index;
201
- const left = this.getLeftChildIndex(index);
202
- const right = this.getRightChildIndex(index);
203
-
204
- if (left < size && this.heap[left] !== undefined && this.compare(this.heap[left]!, this.heap[largest]!) > 0) {
205
- largest = left;
206
- }
207
-
208
- if (right < size && this.heap[right] !== undefined && this.compare(this.heap[right]!, this.heap[largest]!) > 0) {
209
- largest = right;
210
- }
211
-
212
- if (largest === index) {
213
- break;
214
- }
215
-
216
- this.swap(index, largest);
217
- index = largest;
218
- }
219
- }
220
- }
221
-
222
- // Type Guards
223
- export const isMinHeap = <T>(heap: Heap<T>): heap is MinHeap<T> => {
224
- return heap instanceof MinHeap;
225
- };
226
-
227
- export const isMaxHeap = <T>(heap: Heap<T>): heap is MaxHeap<T> => {
228
- return heap instanceof MaxHeap;
229
- };
230
-
231
- /**
232
- * Custom comparator for large numbers
233
- */
234
- export function createLargeNumberComparator(): (a: bigint, b: bigint) => number {
235
- return (a, b) => {
236
- return a > b ? 1 : a < b ? -1 : 0;
237
- };
1
+
2
+ /**
3
+ * Represents the result of a comparison operation
4
+ * -1: first value is less than second value
5
+ * 0: values are equal
6
+ * 1: first value is greater than second value
7
+ */
8
+ export type ComparisonResult = -1 | 0 | 1;
9
+
10
+ /**
11
+ * Generic comparator function type for heap elements
12
+ */
13
+ export type Comparator<T> = (a: T, b: T) => ComparisonResult;
14
+
15
+ /**
16
+ * Abstract base heap class implementing common heap operations
17
+ */
18
+ abstract class Heap<T> {
19
+ protected heap: T[];
20
+ protected readonly compare: Comparator<T>;
21
+
22
+ constructor(comparator: Comparator<T>) {
23
+ this.heap = [];
24
+ this.compare = comparator;
25
+ }
26
+
27
+ /**
28
+ * Gets the size of the heap
29
+ */
30
+ public size(): number {
31
+ return this.heap.length;
32
+ }
33
+
34
+ /**
35
+ * Checks if the heap is empty
36
+ */
37
+ public isEmpty(): boolean {
38
+ return this.heap.length === 0;
39
+ }
40
+
41
+ /**
42
+ * Peeks at the root element without removing it
43
+ */
44
+ public peek(): T | undefined {
45
+ return this.heap[0];
46
+ }
47
+
48
+ /**
49
+ * Inserts a new element into the heap
50
+ */
51
+ public push(value: T): void {
52
+ this.heap.push(value);
53
+ this.siftUp(this.heap.length - 1);
54
+ }
55
+
56
+ /**
57
+ * Removes and returns the root element
58
+ */
59
+ public pop(): T | undefined {
60
+ if (this.isEmpty()) {
61
+ return undefined;
62
+ }
63
+
64
+ const root = this.heap[0];
65
+ const last = this.heap.pop()!;
66
+
67
+ if (!this.isEmpty()) {
68
+ this.heap[0] = last;
69
+ this.siftDown(0);
70
+ }
71
+
72
+ return root;
73
+ }
74
+
75
+ /**
76
+ * Removes all elements from the heap
77
+ */
78
+ public clear(): void {
79
+ this.heap = [];
80
+ }
81
+
82
+ /**
83
+ * Creates a heap from an array of elements
84
+ */
85
+ public static heapify<T extends {}>(array: T[], comparator: Comparator<T>): Heap<T> {
86
+ const heap = this instanceof MinHeap ? new MinHeap(comparator) : new MaxHeap(comparator);
87
+ array.forEach(item => heap.push(item));
88
+ return heap;
89
+ }
90
+
91
+ /**
92
+ * Gets the parent index of a node
93
+ */
94
+ protected getParentIndex(index: number): number {
95
+ return Math.floor((index - 1) / 2);
96
+ }
97
+
98
+ /**
99
+ * Gets the left child index of a node
100
+ */
101
+ protected getLeftChildIndex(index: number): number {
102
+ return 2 * index + 1;
103
+ }
104
+
105
+ /**
106
+ * Gets the right child index of a node
107
+ */
108
+ protected getRightChildIndex(index: number): number {
109
+ return 2 * index + 2;
110
+ }
111
+
112
+ /**
113
+ * Swaps two elements in the heap
114
+ */
115
+ protected swap(i: number, j: number): void {
116
+ const temp = this.heap[i]!;
117
+ this.heap[i] = this.heap[j]!;
118
+ this.heap[j] = temp;
119
+ }
120
+
121
+ /**
122
+ * Moves an element up the heap until heap property is satisfied
123
+ */
124
+ protected abstract siftUp(index: number): void;
125
+
126
+ /**
127
+ * Moves an element down the heap until heap property is satisfied
128
+ */
129
+ protected abstract siftDown(index: number): void;
130
+ }
131
+
132
+ /**
133
+ * MinHeap implementation where the root is the smallest element
134
+ */
135
+ export class MinHeap<T> extends Heap<T> {
136
+ constructor(comparator: Comparator<T>) {
137
+ super(comparator);
138
+ }
139
+
140
+ protected siftUp(index: number): void {
141
+ while (index > 0) {
142
+ const parentIndex = this.getParentIndex(index);
143
+ if (this.compare(this.heap[index]!, this.heap[parentIndex]!) >= 0) {
144
+ break;
145
+ }
146
+ this.swap(index, parentIndex);
147
+ index = parentIndex;
148
+ }
149
+ }
150
+
151
+ protected siftDown(index: number): void {
152
+ const size = this.heap.length;
153
+
154
+ while (true) {
155
+ let smallest = index;
156
+ const left = this.getLeftChildIndex(index);
157
+ const right = this.getRightChildIndex(index);
158
+
159
+ if (left < size && this.compare(this.heap[left]!, this.heap[smallest]!) < 0) {
160
+ smallest = left;
161
+ }
162
+
163
+ if (right < size && this.heap[right] !== undefined && this.compare(this.heap[right] as T, this.heap[smallest] as T) < 0) {
164
+ smallest = right;
165
+ }
166
+
167
+ if (smallest === index) {
168
+ break;
169
+ }
170
+
171
+ this.swap(index, smallest);
172
+ index = smallest;
173
+ }
174
+ }
175
+ }
176
+
177
+ /**
178
+ * MaxHeap implementation where the root is the largest element
179
+ */
180
+ export class MaxHeap<T> extends Heap<T> {
181
+ constructor(comparator: Comparator<T>) {
182
+ super(comparator);
183
+ }
184
+
185
+ protected siftUp(index: number): void {
186
+ while (index > 0) {
187
+ const parentIndex = this.getParentIndex(index);
188
+ if (this.compare(this.heap[index]!, this.heap[parentIndex]!) <= 0) {
189
+ break;
190
+ }
191
+ this.swap(index, parentIndex);
192
+ index = parentIndex;
193
+ }
194
+ }
195
+
196
+ protected siftDown(index: number): void {
197
+ const size = this.heap.length;
198
+
199
+ while (true) {
200
+ let largest = index;
201
+ const left = this.getLeftChildIndex(index);
202
+ const right = this.getRightChildIndex(index);
203
+
204
+ if (left < size && this.heap[left] !== undefined && this.compare(this.heap[left]!, this.heap[largest]!) > 0) {
205
+ largest = left;
206
+ }
207
+
208
+ if (right < size && this.heap[right] !== undefined && this.compare(this.heap[right]!, this.heap[largest]!) > 0) {
209
+ largest = right;
210
+ }
211
+
212
+ if (largest === index) {
213
+ break;
214
+ }
215
+
216
+ this.swap(index, largest);
217
+ index = largest;
218
+ }
219
+ }
220
+ }
221
+
222
+ // Type Guards
223
+ export const isMinHeap = <T>(heap: Heap<T>): heap is MinHeap<T> => {
224
+ return heap instanceof MinHeap;
225
+ };
226
+
227
+ export const isMaxHeap = <T>(heap: Heap<T>): heap is MaxHeap<T> => {
228
+ return heap instanceof MaxHeap;
229
+ };
230
+
231
+ /**
232
+ * Custom comparator for large numbers
233
+ */
234
+ export function createLargeNumberComparator(): (a: bigint, b: bigint) => number {
235
+ return (a, b) => {
236
+ return a > b ? 1 : a < b ? -1 : 0;
237
+ };
238
238
  }
File without changes