Skip to content

Instantly share code, notes, and snippets.

@miku
Last active August 29, 2015 14:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save miku/9500f848bc99f4f0a639 to your computer and use it in GitHub Desktop.
segmenttree in Go
#!/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()
package main
import "log"
type IntervalTree struct {}
func main() {
tree := NewSegTree()
tree.Insert(3, 10)
tree.Insert(11, 13)
tree.Insert(2, 8)
}
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