-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/scala/scalang/util/concurrent/ConcurrentHashSet.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package scalang.util.concurrent; | ||
|
||
import java.util.AbstractSet; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
class ConcurrentHashSet[E] extends AbstractSet[E] { | ||
|
||
val V = ""; | ||
|
||
val map = new ConcurrentHashMap[E,Object] | ||
|
||
override def add(obj: E) = { | ||
map.putIfAbsent(obj, V) == null; | ||
} | ||
|
||
override def contains(obj: Object) = { | ||
map.containsKey(obj); | ||
} | ||
|
||
override def remove(obj: Object) = { | ||
map.remove(obj) == V; | ||
} | ||
|
||
override def size() = { | ||
map.size(); | ||
} | ||
|
||
override def clear() { | ||
map.clear(); | ||
} | ||
|
||
override def iterator() = { | ||
map.keySet().iterator(); | ||
} | ||
|
||
} |