github.com/better-concurrent/guc@v0.0.0-20190520022744-eb29266403a1/collection.go (about) 1 package guc 2 3 import "time" 4 5 // this interface imposes basic operations on objects 6 type Object interface { 7 Equals(i interface{}) bool 8 } 9 10 // this interface is used for ordering the objects of each struct 11 type Comparable interface { 12 CompareTo(i interface{}) int 13 } 14 15 // this interface represents the function that compares two objects 16 type Comparator interface { 17 Compare(o1, o2 interface{}) int 18 } 19 20 type Iterator interface { 21 HasNext() bool 22 Next() interface{} 23 Remove() 24 ForEachRemaining(consumer func(i interface{})) 25 } 26 27 type Iterable interface { 28 Iterator() Iterator 29 ForEach(consumer func(i interface{})) 30 } 31 32 type Collection interface { 33 Iterable 34 Size() int 35 IsEmpty() bool 36 Contains(i interface{}) bool 37 ToArray() []interface{} 38 FillArray(arr []interface{}) []interface{} 39 40 Add(i interface{}) bool 41 Remove(i interface{}) bool 42 ContainsAll(coll Collection) bool 43 AddAll(coll Collection) bool 44 RemoveAll(coll Collection) bool 45 RemoveIf(predicate func(i interface{}) bool) bool 46 RetainAll(coll Collection) bool 47 Clear() 48 Equals(i interface{}) bool 49 HashCode() int 50 } 51 52 type Queue interface { 53 Collection 54 55 // default inherits 56 // Add(i interface{}) bool 57 58 Offer(i interface{}) bool 59 // retrieve and remove head 60 // panic if empty 61 RemoveHead() interface{} 62 // retrieve and remove head 63 // return nil if empty 64 Poll() interface{} 65 // retrieve head of the queue 66 // panic if empty 67 Element() interface{} 68 // retrieve head of the queue 69 // return nil if empty 70 Peek() interface{} 71 } 72 73 type BlockingQueue interface { 74 Queue 75 76 // default inherits 77 // Add(i interface{}) bool 78 // Offer(i interface{}) bool 79 // Remove(i interface{}) bool 80 // Contains(i interface{}) bool 81 82 Put(i interface{}) 83 OfferWithTimeout(i interface{}, t time.Duration) bool 84 Take() interface{} 85 PollWithTimeout(t time.Duration) interface{} 86 RemainingCapacity() int 87 DrainTo(coll Collection) int 88 DrainToWithLimit(coll Collection, max int) int 89 }