Added contains.

master
Robinson 2023-08-10 16:53:52 -06:00
parent 726c0aed62
commit 4e9aeb1854
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
1 changed files with 10 additions and 6 deletions

View File

@ -39,6 +39,15 @@ class ConcurrentIterator<T: Any> {
this.loadFactor = loadFactor
}
/**
* single writer principle!
* called from within SYNCHRONIZE
*/
@Synchronized
fun contains(entry: T): Boolean {
return entries.contains(entry)
}
/**
* single writer principle!
* called from within SYNCHRONIZE
@ -98,8 +107,6 @@ class ConcurrentIterator<T: Any> {
*/
@Synchronized
fun add(listener: T) {
@Suppress("UNCHECKED_CAST")
var head: ConcurrentEntry<T>? = headREF[this] as ConcurrentEntry<T>?
if (!entries.containsKey(listener)) {
head = ConcurrentEntry(listener, head)
entries.put(listener, head)
@ -130,12 +137,9 @@ class ConcurrentIterator<T: Any> {
*/
@Synchronized
fun remove(concurrentEntry: ConcurrentEntry<T>): Boolean {
@Suppress("UNCHECKED_CAST")
var head: ConcurrentEntry<T>? = headREF[this] as ConcurrentEntry<T>?
if (concurrentEntry == head) {
// if it was second, now it's first
head = head.next()
head = head!!.next()
//oldHead.clear(); // optimize for GC not possible because of potentially running iterators
} else {
concurrentEntry.remove()