Reputation: 1322
Here's the scenario. I am creating a simple session handler in Scala and I need a class that can store lists. The class needs other functions associated with it to function properly.
I will be accessing sessions by a session ID I will rarely be traversing the list I will be constantly adding and removing from the list
My questions:
I am fairly new to Scala so please forgive the elementary question I might be asking. Any assistance would be most appreciated.
Edit: To add to it all...Thread Safty is a factor. The object used must be thread safe or it must be easy to allow for thread safty when adding and removing items by Session ID.
Upvotes: 1
Views: 397
Reputation: 2016
You can use the immutable implementation of HashSet which operations of adding and removing take effectively constant time.
Once this collection is immutable, you'll need to learn the "scala way" of working with collections, how to deal with state and so on. Maybe you'll need to change the way you're working the collections, but this way you won't need to worry about concurrency.
Upvotes: 1
Reputation: 7989
You can use java.util.concurrent.ConcurrentHashMap
- it has best performance with guarantied thread safety.
Upvotes: 2