Skip to content

Instantly share code, notes, and snippets.

put =map(range(1,100), 'printf(''goreplay20191201_%d,'', v:val)')
@onemouth
onemouth / mcount.go
Last active September 22, 2019 06:48
get mcount from go
package main
import (
"C"
"fmt"
"runtime"
"runtime/debug"
"time"
"os/exec"
_ "unsafe"
class MedianFinder:
def __init__(self):
"""
initialize your data structure here.
"""
self.minHeap = []
self.maxHeap = []
def addNum(self, num: int) -> None:
func (m *Map) Add(nodes ...string) {
for _, n := range nodes {
for i := 0; i < m.replicas; i++ {
hash := int(m.hash([]byte(strconv.Itoa(i) + " " + n)))
m.nodes = append(m.nodes, hash)
m.hashMap[hash] = n
}
}
sort.Ints(m.nodes)
}
int ch(int key, int num_buckets) {
random.seed(key);
int b = -1;
int j = 0;
while (j < num_buckets) {
b = j;
double r = random.next();
j = floor((b + 1) / r);
}
return b;
int32_t JumpConsistentHash(uint64_t key, int32_t num_buckets) {
int64_t b = -1, j = 0;
while (j < num_buckets) {
b = j;
key = key * 2862933555777941757ULL + 1;
j = (b + 1) * (double(1LL << 31) / double((key >> 33) + 1));
}
return b;
}
int ch(int key, int num_buckets) {
random.seed(key);
int b = 0;
for (int j = 1; j < num_buckets; j++) {
if (random.next() < 1.0 / (j + 1))
b = j;
}
return b;
}
func (m *Map) Get(key string) string {
hash := int(m.hash([]byte(key)))
idx := sort.Search(len(m.keys),
func(i int) bool { return m.keys[i] >= hash }
)
if idx == len(m.keys) {
idx = 0
}
return m.hashMap[m.keys[idx]]
}
package main
import (
"encoding/base64"
"fmt"
"crypto/hmac"
"crypto/sha256"
)
// ValidMAC reports whether messageMAC is a valid HMAC tag for message.
package main
import (
"encoding/base64"
"fmt"
"crypto/hmac"
"crypto/sha256"
)
// ValidMAC reports whether messageMAC is a valid HMAC tag for message.