Created
October 26, 2015 11:20
-
-
Save malte0811/d628d12e932ec0cd256c to your computer and use it in GitHub Desktop.
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
package tmp; | |
import java.util.Collections; | |
import java.util.Iterator; | |
import java.util.Set; | |
import java.util.concurrent.ConcurrentHashMap; | |
public class Main { | |
public static void main(String[] args) { | |
Set<String> s = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>()); | |
s.add("1"); | |
s.add("2"); | |
s.add("3"); | |
s.add("4"); | |
Iterator<String> it = s.iterator(); | |
System.out.println(it.next()); | |
s.remove("4"); | |
System.out.println(it.next()); | |
System.out.println(it.next()); | |
} | |
} |
Ok, you can ignore my comment on the issue, github did not automatically subscribe me to this thread as it does with prs and issues.
I think pretty much every set(hashset and probably most others as well) is backed by a map <T, Boolean>, so it would not be additional memory.
So, are you ok with me pr'ing that commit?
as you said, every set is backed by a list or map ... the one it is created from of course XD .. but the default implementation for most sets is base of a non-concurrent safe list or hashmap, therefore i was curious if your aproach is properly CME safe and you proved me wrong :D thank you for teaching me a lesson
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
looks fine for me :D with that the
SkipListSet
become historybut why the heck do i have to use Boolean there ???
We exchange a portion of wasted RAM for execution time therefore am i right ?