The UTRoot is the root object of the Universal Tree (UT).
All repositories and working sets agree on the identity of the UTRoot
.
Since all working sets agree on the identity of the UTRoot
, working sets that have no operations
in common have a basis for exchanging operations and merging all the information resulting in a single
tree of objects.
The UTRoot
is defined in the Xc++ language using a $struct as follows:
$struct+ UTRoot isa IPersistable :
model
{
xmap<xstring,xvector<movable<pref<IObject>>>> Map;
}
{
};
The interface IPersistable is implemented in order to be a persistable object having an OID and existing in a PSpace.
The embedded model has a single member named Map
which is an xmap
. An xmap<K,V>
is
a map from K
to V
implemented using a B+Tree.
The idea is to allow applications to register named root objects where the names are UTF-8 strings.
It is convenient to call them root objects even though they are children of the UTRoot
.
Typically only a single site creates the root object for an application and registers it in the UTRoot
.
Other sites must connect to a peer and receive at least one operation in order
to receive the application root.
Using a map keyed by string allows for any number of applications to write data independently to the one UT (to the extent that applications can independently define strings on which to key their data). Developers should take precautions to avoid accidental name clashes, by avoiding overly simple names and trying not to "polute" the UT root namespace with too many entries. It may therefore be appropriate for an application to only add a single entry for all its data. Nevertheless the implementation uses a B+Tree and therefore can deal efficiently with millions or even billions of entries.
Each string is mapped to a xvector<movable<pref<IObject>>>
. A vector allows for resolving
conflicts in cases where applications would like to assume a string is mapped to only one object
(e.g. sites can assume the winner is the 0th entry), without incurring the data loss which
would arise with a map<string,movable<pref<IObject>>>
.
name
is an application defined key into the UTRoot
namespace.
Returns the 0th object, assumed to be of concrete type T
stored under the UTRoot
, keyed by
name
, or returns nullptr
if not found.
template<typename T>
T* GetUTRootEntry(WorkingSetMachine* ws, const xstring& name)