Lets say I have two sets:
set1 = set(("a", "b", 5), ("a", "c", 3))
set2 = set(("a", "b", 3), ("a", "b", 7))
Each item has 3 values:
- first index (first part of the key) e.g. "a"
- second index (second part of the key) e.g. "b"
- third index (timestamp last part of the key) e.g 5
I want to search for all of the elements of set 1, that have the corresponding item in set2, where the corresponding item is any item that has the same value at both the first and second index, but the value of the timestamp of the matching item from the set2 must be lower than the timestamp of the item from the set1.
From the example the matching item would be:
("a", "b", 5) ("a", "b", 3)timestamp of 3 < 5- ā ("a", "b", 5) ("a", "b", 7)
("a", "c", 3) ("a", "b", 3)"c" != "b"("a", "c", 3) ("a", "b", 7)"c" != "b"
Now the problem is I need to search for the items in set2 in n.log(n) time. That is why I am trying to keep the values in the set. If I was looking for the items without the timestamp:
set1 = set(("a", "b"), ("a", "c"))
set2 = set(("a", "b"), ("a", "b"))
I could do:
for item from set1:
if item in set2:
print("Found matching item")
But with the timestamp, I can't figure out how to implement this without two for loops.