-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add .bsp to .gitignore * Extract KeySet and MapKey out of Cache Because they probably going to be shared with ManagedCache * define interface for a ManagedCache * Copy/Paste: cache implementation and cache test for managedCache * Adapt cache implementation and test for ManagedCache * make ManagedCache.get return Managed[Error, Value] instead of UIO[Managed[Error, Value]] * Make ManagedCache work on 2.11 and Scala 3 * Fix doc after Adam's review * fixup! Fix doc after Adam's review * fixup! Fix doc after Adam's review
- Loading branch information
Showing
9 changed files
with
1,474 additions
and
70 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package zio.cache | ||
|
||
/** | ||
* A `KeySet` is a sorted set of keys in the cache ordered by last access. | ||
* For efficiency, the set is implemented in terms of a doubly linked list | ||
* and is not safe for concurrent access. | ||
*/ | ||
private[cache] final class KeySet[Key] { | ||
private[this] var head: MapKey[Key] = null | ||
private[this] var tail: MapKey[Key] = null | ||
|
||
/** | ||
* Adds the specified key to the set. | ||
*/ | ||
def add(key: MapKey[Key]): Unit = | ||
if (key ne tail) { | ||
if (tail ne null) { | ||
val previous = key.previous | ||
val next = key.next | ||
if (next ne null) { | ||
key.next = null | ||
if (previous ne null) { | ||
previous.next = next | ||
next.previous = previous | ||
} else { | ||
head = next | ||
head.previous = null | ||
} | ||
} | ||
tail.next = key | ||
key.previous = tail | ||
tail = key | ||
} else { | ||
head = key | ||
tail = key | ||
} | ||
} | ||
|
||
/** | ||
* Removes the lowest priority key from the set. | ||
*/ | ||
def remove(): MapKey[Key] = { | ||
val key = head | ||
if (key ne null) { | ||
val next = key.next | ||
if (next ne null) { | ||
key.next = null | ||
head = next | ||
head.previous = null | ||
} else { | ||
head = null | ||
tail = null | ||
} | ||
} | ||
key | ||
} | ||
} |
Oops, something went wrong.