This file contains 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
// free with free(arr); | |
static int* new_union(int n) { | |
int* arr = malloc(sizeof(int)*n); | |
for (int i=0; i<n; i++) arr[i] = i; | |
return arr; | |
} | |
// Implements path compression | |
static int get_parent(int* arr, int i) { | |
if (arr[i] == i) return i; |
This file contains 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
@ECHO OFF | |
REM Automatic Zig Download and Install Script | |
REM Add the variable (as a variable) %ZIGPATH% to user path for usage. | |
REM Requires jq to be installed. | |
SET zigurl=https://ziglang.org/download/index.json | |
SET zigjson=.\zigmaster.json | |
ECHO Fetching Zig Master .json | |
curl -o %zigjson% %zigurl% |
This file contains 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
/* | |
Upper and lower bounds. | |
Upper bound: First where target < array[i] | |
Lower bound: First where !(array[i] < target) | |
Assume a 3 way comparision returns this. | |
[-1 -1 -1 -1 0 0 0 0 0 1 1 1 1 1] | |
^ Lower bound. ^ | |
Upper bound. | |
*/ |
This file contains 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
// Triangle indexes | |
// if you have a set of N items with indexes. | |
// 0,1,2,3, ... , N-1 | |
// You want a linear index for every pair i,j, i != j. | |
// N Choose 2. | |
inline int triangleSize(int N) { | |
return N*(N-1)/2; | |
} |
This file contains 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
// Multi Dimensional Slices in Zig | |
// Sort of akin to ndarrays in Python's numpy | |
const std = @import("std"); | |
const runtime_safety = std.debug.runtime_safety; | |
const mem = std.mem; | |
const NDSliceErrors = error{ | |
InsufficientBufferSize, | |
ZeroLengthDimensionsNotSupported, |