1 package it.unimi.dsi.fastutil; 2 3 23 24 import java.util.Comparator ; 25 import java.util.NoSuchElementException ; 26 27 31 32 public class IndirectDoublePriorityQueues { 33 34 private IndirectDoublePriorityQueues() {} 35 36 41 42 public static class EmptyIndirectDoublePriorityQueue extends IndirectPriorityQueues.EmptyIndirectPriorityQueue { 43 44 protected EmptyIndirectDoublePriorityQueue() {} 45 46 public int secondaryFirst() { throw new NoSuchElementException (); } 47 public int secondaryLast() { throw new NoSuchElementException (); } 48 public Comparator secondaryComparator() { return null; } 49 50 } 51 52 54 55 public final static EmptyIndirectDoublePriorityQueue EMPTY_QUEUE = new EmptyIndirectDoublePriorityQueue(); 56 57 58 59 60 public static class SynchronizedIndirectDoublePriorityQueue<K> implements IndirectDoublePriorityQueue<K> { 61 62 public static final long serialVersionUID = -7046029254386353129L; 63 64 final protected IndirectDoublePriorityQueue<K> q; 65 final protected Object sync; 66 67 protected SynchronizedIndirectDoublePriorityQueue( final IndirectDoublePriorityQueue<K> q, final Object sync ) { 68 this.q = q; 69 this.sync = sync; 70 } 71 72 protected SynchronizedIndirectDoublePriorityQueue( final IndirectDoublePriorityQueue<K> q ) { 73 this.q = q; 74 this.sync = this; 75 } 76 77 public void enqueue( int x ) { synchronized( sync ) { q.enqueue( x ); } } 78 public int dequeue() { synchronized( sync ) { return q.dequeue(); } } 79 public int first() { synchronized( sync ) { return q.first(); } } 80 public int last() { synchronized( sync ) { return q.last(); } } 81 public int secondaryFirst() { synchronized( sync ) { return q.secondaryFirst(); } } 82 public int secondaryLast() { synchronized( sync ) { return q.secondaryLast(); } } 83 public boolean isEmpty() { synchronized( sync ) { return q.isEmpty(); } } 84 public int size() { synchronized( sync ) { return q.size(); } } 85 public void clear() { synchronized( sync ) { q.clear(); } } 86 public void changed() { synchronized( sync ) { q.changed(); } } 87 public void allChanged() { synchronized( sync ) { q.allChanged(); } } 88 public void changed( int i ) { synchronized( sync ) { q.changed( i ); } } 89 public void remove( int i ) { synchronized( sync ) { q.remove( i ); } } 90 public Comparator <? super K> comparator() { synchronized( sync ) { return q.comparator(); } } 91 public Comparator <? super K> secondaryComparator() { synchronized( sync ) { return q.secondaryComparator(); } } 92 } 93 94 95 100 public static <K> IndirectDoublePriorityQueue<K> synchronize( final IndirectDoublePriorityQueue<K> q ) { return new SynchronizedIndirectDoublePriorityQueue<K>( q ); } 101 102 108 109 public static <K> IndirectDoublePriorityQueue<K> synchronize( final IndirectDoublePriorityQueue<K> q, final Object sync ) { return new SynchronizedIndirectDoublePriorityQueue<K>( q, sync ); } 110 111 } 112 | Popular Tags |