// Path: src/main/java/rxbroadcast/time/LamportClock.java
// public final class LamportClock {
//     private final Lock lock;
// 
//     private long currentTime;
// 
//     LamportClock(final Lock lock) {
//         this.lock = lock;
//     }
// 
//     /**
//      * Creates an instance of {@code LamportClock}.
//      */
//     public LamportClock() {
//         this(new ReentrantLock());
//     }
// 
//     /**
//      * Returns the current clock timestamp.
//      * @return the current clock timestamp.
//      */
//     public long time() {
//         lock.lock();
//         try {
//             return currentTime;
//         } finally {
//             lock.unlock();
//         }
//     }
// 
//     /**
//      * Updates this clock to account for the given incoming timestamp.
//      *
//      * If the given timestamp is larger than the current clock's time,
//      * the clock will set its timestamp to the given value, and the
//      * next timestamp generated by the instance will be {@code incoming + 1}.
//      * @param incoming the incoming timestamp
//      */
//     public void set(final long incoming) {
//         lock.lock();
//         try {
//             currentTime = incoming;
//         } finally {
//             lock.unlock();
//         }
//     }
// 
//     public <T> T tick(@NotNull final LongFunction<T> ticker) {
//         lock.lock();
//         try {
//             currentTime = currentTime + 1;
//             return ticker.apply(currentTime);
//         } finally {
//             lock.unlock();
//         }
//     }
// 
//     public <T> T tick(@NotNull final Supplier<T> ticker) {
//         lock.lock();
//         try {
//             currentTime = currentTime + 1;
//             return ticker.get();
//         } finally {
//             lock.unlock();
//         }
//     }
// 
//     @NotNull
//     @Override
//     public final String toString() {
//         lock.lock();
//         try {
//             return String.format("LamportClock{currentTime=%d}", currentTime);
//         } finally {
//             lock.unlock();
//         }
//     }
// }


import rxbroadcast.time.LamportClock;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
package rxbroadcast;



public final class CausalOrder<T> implements BroadcastOrder<VectorTimestamped<T>, T> {
    private final class DelayQueueEntry {
        final Sender sender;

        final VectorTimestamped<T> message;

        private DelayQueueEntry(final Sender sender, final VectorTimestamped<T> message) {
            this.sender = sender;
            this.message = message;
        }
    }

    private final Sender me;

// Path: src/main/java/rxbroadcast/time/LamportClock.java
// public final class LamportClock {
//     private final Lock lock;
// 
//     private long currentTime;
// 
//     LamportClock(final Lock lock) {
//         this.lock = lock;
//     }
// 
//     /**
//      * Creates an instance of {@code LamportClock}.
//      */
//     public LamportClock() {
//         this(new ReentrantLock());
//     }
// 
//     /**
//      * Returns the current clock timestamp.
//      * @return the current clock timestamp.
//      */
//     public long time() {
//         lock.lock();
//         try {
//             return currentTime;
//         } finally {
//             lock.unlock();
//         }
//     }
// 
//     /**
//      * Updates this clock to account for the given incoming timestamp.
//      *
//      * If the given timestamp is larger than the current clock's time,
//      * the clock will set its timestamp to the given value, and the
//      * next timestamp generated by the instance will be {@code incoming + 1}.
//      * @param incoming the incoming timestamp
//      */
//     public void set(final long incoming) {
//         lock.lock();
//         try {
//             currentTime = incoming;
//         } finally {
//             lock.unlock();
//         }
//     }
// 
//     public <T> T tick(@NotNull final LongFunction<T> ticker) {
//         lock.lock();
//         try {
//             currentTime = currentTime + 1;
//             return ticker.apply(currentTime);
//         } finally {
//             lock.unlock();
//         }
//     }
// 
//     public <T> T tick(@NotNull final Supplier<T> ticker) {
//         lock.lock();
//         try {
//             currentTime = currentTime + 1;
//             return ticker.get();
//         } finally {
//             lock.unlock();
//         }
//     }
// 
//     @NotNull
//     @Override
//     public final String toString() {
//         lock.lock();
//         try {
//             return String.format("LamportClock{currentTime=%d}", currentTime);
//         } finally {
//             lock.unlock();
//         }
//     }
// }


// Path: src/main/java/rxbroadcast/CausalOrder.java
import rxbroadcast.time.LamportClock;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

package rxbroadcast;



public final class CausalOrder<T> implements BroadcastOrder<VectorTimestamped<T>, T> {
    private final class DelayQueueEntry {
        final Sender sender;

        final VectorTimestamped<T> message;

        private DelayQueueEntry(final Sender sender, final VectorTimestamped<T> message) {
            this.sender = sender;
            this.message = message;
        }
    }

    private final Sender me;

    private final Map<Sender, LamportClock> vt = new ConcurrentHashMap<>();