segmenttree in Go
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/env python | |
""" | |
Compress n strings into a single on, preserving order. | |
""" | |
pad = 20 | |
pairs = [ | |
[["2004", "45", "109"], ["2004", "Someextralong", ""]], | |
[["2004", "45", "109"], ["2004", "07", "AAA"]], | |
[["2004", "XX", "23"], ["2004", "XV", "1"]], | |
[["2004", "XX", "23"], ["21830219398021832198309", "XV", "1"]], | |
[["2004", "XX", "23"], ["Z" * pad, "Z" * pad, "Z" * pad]], | |
] | |
def compact(t): | |
""" compact a tuple """ | |
return "".join([str(val).zfill(pad) for val in t]) | |
def main(): | |
for pair in pairs: | |
a = compact(pair[0]) | |
b = compact(pair[1]) | |
print(sorted([a, b])) | |
if __name__ == '__main__': | |
main() |
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 "log" | |
type IntervalTree struct {} | |
func main() { | |
tree := NewSegTree() | |
tree.Insert(3, 10) | |
tree.Insert(11, 13) | |
tree.Insert(2, 8) | |
} |
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 "log" | |
type SegTree struct { | |
} | |
func NewSegTree() SegTree { | |
return SegTree{} | |
} | |
func (t SegTree) Insert(a, b int64) { | |
log.Printf("inserting [%d, %d]\n", a, b) | |
} | |
func main() { | |
tree := NewSegTree() | |
tree.Insert(3, 10) | |
tree.Insert(11, 13) | |
tree.Insert(2, 8) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment