Context: After 3 decades of coding in C++, I am learning Swift. So a "tip o' the hat" and a great big thankyou to @Doug_Gregor for his wonderful 10-part series "Swift for C++ Practitioners".
My current project is a memory-resident RDF*-style graph database supporting a smartphone app. The components of the graph edges are effectively strings, often following IRI syntax and sharing prefixes of significant length. A common design choice in graph database implementations is to enter strings into a dictionary and then to use dictionary indices in lieu of string pointers. This can lead to a very significant reduction in the size of one's edge object. It also renders the equality predicate on edge components O(1).
In my application, a string to be interned will always start life as a standard Swift String. But I also need to be able to turn a dictionary index efficiently back into a Swift String.
To minimize the size of a stored sting, the number of memory indirects, and the amount of heap fragmentation, I will intern strings into large, stable fixed-size arrays of UInt64s. Of course this means that strings (including a trailing null byte) will always occupy a multiple of 8 bytes. Some number of leader bytes will record the string's length and an ASCII flag.
Given that, once interned, a string is effectively both immutable and eternal, my hope is for an API to be able to construct in O(1) time an immortal (non-ARC) Swift String pointing to the interned string body. Is that possible?