This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Delete any objects tagged for garbage collection. | |
| */ | |
| export const cleanup = (exclude?: Array<Manifold | CrossSection>) => { | |
| const deleteUnlessExcluded = getDeleter(exclude); | |
| for (const obj of memoryRegistry) { | |
| // decompose result is an array of manifolds | |
| if (obj instanceof Array) | |
| for (const elem of obj) deleteUnlessExcluded(elem); | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Implementation of "An Efficiently Computable Metric | |
| * for Comparing Polygonal Shapes," by Arkin, Chew, Huttenlocher, | |
| * Kedem, and Mitchel (undated). This expands a little on the | |
| * cited reference to achieve O(n) space and O(mn log n) | |
| * run time. | |
| * | |
| * This could be improved to O(min m,n) and O(mn log min m,n) | |
| * by selecting the smallest of the 2 polys to create the initial | |
| * event heap. See init_events(). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Color = 'r' | 'b'; | |
| type NullableNode<K, V> = Node<K, V> | null; | |
| type Node<K, V> = { | |
| value: V; | |
| color: Color; | |
| kids: [NullableNode<K, V>, NullableNode<K, V>]; | |
| }; | |
| export class TreeMap<K, V> { | |
| private root: NullableNode<K, V> = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ImagesLoader { | |
| private readonly images: Map<string, HTMLImageElement>; | |
| private readonly pendingActions: ((images: Map<string, HTMLImageElement>) => void)[] = []; | |
| public readonly errors = new Set<string>(); | |
| private remainingCount: number; | |
| constructor(urls: string[]) { | |
| this.remainingCount = urls.length; | |
| this.images = new Map<string, HTMLImageElement>( | |
| ((loader) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| typedef struct node_s { | |
| struct node_s *parent; | |
| int size; | |
| int value; | |
| } DISJOINT_SET; | |
| DISJOINT_SET *make_set(int value) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <ctype.h> | |
| #define ACTIVE_BUZZER 12 | |
| char s[256]; | |
| int n = 0, p = 0; | |
| void setup() { | |
| delay(1000); | |
| pinMode(LED_BUILTIN, OUTPUT); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| static int med3(int a, int b, int c) { | |
| return a < b | |
| ? c < a ? a : (c < b ? c : b) | |
| : c > a ? a : (c > b ? c : b); | |
| } | |
| static void swap(int *a, int i, int j) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # For any 0 <= k < fact(n), return a unique permutation of [0..n-1]. | |
| # Functional inverse of number_from_perm(). | |
| def perm_from_number(n, k): | |
| a = list(range(n)) | |
| p = [] | |
| for d in range(2, n + 1): | |
| p.append(k % d) | |
| k //= d | |
| t = n - 1 | |
| for i in reversed(p): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| static int med3(int a, int b, int c) { | |
| return a < b | |
| ? c < a ? a : (c < b ? c : b) | |
| : c > a ? a : (c > b ? c : b); | |
| } | |
| static void swap(int *a, int i, int j) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| typedef struct edge_s { | |
| struct edge_s *next; | |
| int to; | |
| } Edge; | |
| typedef struct vertex_s { | |
| Edge *edges; |
NewerOlder