Skip to content

Commit

Permalink
Add method to convert to a linked map.
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethshackleton committed Jun 21, 2024
1 parent 14168cd commit d01470f
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ class FastStampedStringMap<T>(
return currentStamp
}

internal fun asLinkedMap(
maxSize: Int = size,
disposal: (T) -> Unit
) = FastLinkedStringMap(
maxSize = maxSize,
capacity = maxSize,
accessOrder = true,
disposal = disposal
).apply {
entries().sortedBy {
(it as StampedEntry<T>).stamp
}.forEach {
addAssociation(it.index, it.hashCode, it.key, it.value!!)
}
}

private fun entries(): Iterable<Entry<T>> = store.flatMap {
sequence {
var current = it
Expand Down

0 comments on commit d01470f

Please sign in to comment.