def save(self, doc):
        if doc.id:
            return self.update(doc)
        else:
            return self.insert(doc)
def insert(root, key):
    left, right = split(root, key)
    return merge(merge(left, Treap(key)), right)