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
put =map(range(1,100), 'printf(''goreplay20191201_%d,'', v:val)') |
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
package main | |
import ( | |
"C" | |
"fmt" | |
"runtime" | |
"runtime/debug" | |
"time" | |
"os/exec" | |
_ "unsafe" |
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
class MedianFinder: | |
def __init__(self): | |
""" | |
initialize your data structure here. | |
""" | |
self.minHeap = [] | |
self.maxHeap = [] | |
def addNum(self, num: int) -> None: |
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
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) | |
} |
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
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; |
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
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; | |
} |
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
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; | |
} |
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
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]] | |
} |
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
package main | |
import ( | |
"encoding/base64" | |
"fmt" | |
"crypto/hmac" | |
"crypto/sha256" | |
) | |
// ValidMAC reports whether messageMAC is a valid HMAC tag for message. |
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
package main | |
import ( | |
"encoding/base64" | |
"fmt" | |
"crypto/hmac" | |
"crypto/sha256" | |
) | |
// ValidMAC reports whether messageMAC is a valid HMAC tag for message. |
NewerOlder