python/comparator_usage.py
Matej Focko 457ab180d0
feat: add example usage of comparator
Signed-off-by: Matej Focko <mfocko@redhat.com>
2022-05-07 15:42:06 +02:00

47 lines
882 B
Python

from comparator import Comparator
from avl import AVLTree
from wavl import WAVLTree
import logging
import random
def main():
logging.basicConfig(level=logging.DEBUG)
t = Comparator(AVLTree(), WAVLTree())
# t = WAVLTree()
values = []
for _ in range(42):
x = random.randint(1, 100)
while x in values:
x = random.randint(1, 100)
values.append(x)
t.insert(x)
for _ in range(5):
x = random.choice(values)
values.remove(x)
t.delete(x)
for _ in range(42):
x = random.randint(1, 100)
while x in values:
x = random.randint(1, 100)
values.append(x)
t.insert(x)
for _ in range(5):
x = random.choice(values)
values.remove(x)
t.delete(x)
print(t)
# print(t.are_equal)
if __name__ == "__main__":
main()