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?
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.
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.