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
I want you to act as a senior {language} programmer. | |
The question will be a about the {language} programming language. | |
I want you to answer only with the fenced code block. | |
I want you to add an language identifier to the fenced code block. | |
Do not write explanations. |
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
// A Fast, Minimal Memory, Consistent Hash Algorithm: https://arxiv.org/pdf/1406.2294.pdf | |
local MAX_INT = 281474976710656; // 48-bit integers are ok in jsonnet. | |
local NIBBLES = 12; // 12 hex digits in a 48-bit number. | |
// "random numbers should not be generated with a method chosen at random. -- D. Knuth | |
// And yet, due to lack of 64-bit integer arithmetic in jsonnet, this seems to work decently. | |
local nextRandom(n) = std.parseHex(std.slice(std.md5(std.toString(n)), 0, NIBBLES, 1)); | |
{ |
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
/ jumphost https://arxiv.org/pdf/1406.2294.pdf | |
/ usage: jh[k;n] | |
/ k: 64-bit key; n: num_buckets | |
/ Targeting the K6 and K8 dialects. Tested with ngn/k and shakti 2021.07.10 | |
rsh:{$[x<0;1073741823+_(x-9223372036854775808)%8589934592;_x%8589934592]} | |
jhr:{[b;j;k;n] b:j;k:1+k*2862933555777941757;j:_(b+1)*2147483648%1+rsh[k]; $[j<n;jhr[b;j;k;n];b]} | |
jh:jhr[-1;0] | |
/ k doesn't have unsigned integers nor does have bitshifts | |
/ the rsh function shifts right by dividing after manually clearing the MSB |
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
// "hide" a field with a given field name or matching a given predicate. | |
// Optionally, change the value of the field being mapped. | |
// | |
// This is useful until jsonnet gains the ability of using "::" in object comprehension, see | |
// https://github.com/google/jsonnet/issues/312#issuecomment-1580533298 | |
local hide(obj, field=null, pred=function(name) (name == field), map=function(value) value) = | |
std.foldl( | |
function(acc, f) | |
if pred(f.key) then | |
acc { [f.key]:: map(f.value) } |
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
{ | |
"additionalProperties": false, | |
"properties": { | |
"apiVersion": { | |
"type": "string" | |
}, | |
"kind": { | |
"type": "string" | |
}, | |
"metadata": { |
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
local to_overlay = import 'to_overlay.libsonnet'; | |
{ | |
a: { | |
b: { | |
c: 1, | |
d: self.c, | |
h:: 42, | |
}, | |
}, | |
} + to_overlay.toOverlay(std.parseYaml(||| |
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
#!/usr/bin/perl -w | |
# | |
# stackcollapse-perf.pl collapse perf samples into single lines. | |
# | |
# Parses a list of multiline stacks generated by "perf script", and | |
# outputs a semicolon separated stack followed by a space and a count. | |
# If memory addresses (+0xd) are present, they are stripped, and resulting | |
# identical stacks are colased with their counts summed. | |
# | |
# USAGE: ./stackcollapse-perf.pl [options] infile > outfile |
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
#![allow(dead_code)] | |
use rendezvous_hash::RendezvousNodes; | |
use rendezvous_hash::{Capacity, WeightedNode}; | |
use std::collections::hash_map::DefaultHasher; | |
use std::collections::{HashMap, HashSet}; | |
use std::hash::{BuildHasher, BuildHasherDefault, Hash, Hasher}; | |
const JUMP: u64 = 1 << 31; | |
/// Takes a 64 bit key and the number of buckets, outputs a bucket number `0..buckets`. |
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
#![allow(dead_code)] | |
use rendezvous_hash::RendezvousNodes; | |
use rendezvous_hash::{Capacity, WeightedNode}; | |
use std::collections::hash_map::DefaultHasher; | |
use std::collections::{HashMap, HashSet}; | |
use std::hash::BuildHasherDefault; | |
type MyBuildHasher = BuildHasherDefault<DefaultHasher>; | |
fn main() { |
NewerOlder