Atomic (read-only) snapshot and clear for TrieMap?

I’d like to recycle a discussion regarding a feature request for TrieMap from scala-users. The goal is to provide an atomic shapshot-and-clear method to the existing TrieMap interface.

I proposed an implementation drawing from clear and readOnlySnapshot. It makes use of the private method RDCSS_ROOT – hence it is difficult to see how to implement short of duplicating TrieMap.scala:

@tailrec def snapshotAndClear(): scala.collection.Map[K, V]  = {
    val r = RDCSS_READ_ROOT()
    val expmain = r.gcasRead(this)
    if (RDCSS_ROOT(r, expmain, INode.newRootNode[K, V](equality) )) new TrieMap(r, null, hashing, equality)
    else snapshotAndClear()
  }

The name readOnlySnapshotAndClear is perhaps more in-line with the existing interface’s naming – my feeling was that this was too long.

Would this make sense as a contribution? If so, would scala-library-next be the appropriate next step?

1 Like

Hi @aschweig. Unfortunately the Scala standard library is currently not open for new additions. There is however a proposal currently being discussed to change that: https://github.com/scala/improvement-proposals/pull/54.

scala-library-next is an option in principle, however that library hasn’t seen much support so far, there are no releases. Also, the implementation you propose uses the private RDCSS_ROOT which cannot be accessed externally.

I don’t think it was ever intended to have releases? AFAIK, scala-library-next is intended to be the holding bin for exactly this sort of thing – additions that are potentially desireable to add to stdlib once that reopens to new content.

In that case, wouldn’t it be better to just start a 2.14.x or maybe-future or fingers-crossed branch in the scala/scala repo?

scala-library-next was intended to have releases, so that people could easily try the additions out, or even depend on scala-library-next in their projects.

4 Likes