Hello.
There are such classes: Btree<TKey, TValue>
, page with Page<TKey>
nodes (there is a pointer to the root page in Btree
), the page has a list of SortedList<TKey, Node>
nodes (in Node, except for the DataPosition
and ChildPosition
, nothing is determined), the number of nodes naturally varies from the order of the tree. Save pages and data in a file.
Now the actual question is: how to make the TKey
object TKey
saved to a file and occupy a certain fixed number of bytes there? For example, in the simplest case, if TKey is a string, and string is of different length, then you need to set the length of the maximum string somewhere (that is, the key).
A little thought, nothing smarter than the interface ISizeFixed
came up with. However, it would be nice if the standard primitive types (int, char ...) could be keys without packaging them into a wrapper class that implements this interface.
Are there any other options? Maybe I basically designed the system wrong?
upd0: the need for a fixed size came from the fact that the number of nodes in a page can vary (but there can be no more than 2t-1 there, where t is the tree order), and there can be a lot of these pages in the file and they are tight. Accordingly, when a page is placed in a file, 2t-1 dummy nodes are immediately added to it, and then, with the actual addition of elements, the dummy nodes are replaced with the added element.
Perhaps this can be implemented in a different way, if there are ideas, I will be pleased to know them.
<s> Btree
some more thought, I decided to make several overloads of the Btree
constructor for each of the primitive types, and an overload for objects implementing ISizeFixed
. But I'm still waiting for some other ideas. </ S> Also not good.
In general, I would really like some kind of custom formatter, which during serialization checked the record length and, if it is less than the required one, added the missing bytes (well, threw an exception if the limit was exceeded)
IXmlSerializable
interface? It is not clear, however, how you can serialize an object (for example, a string) with a size of 100 bytes with a limit of 50 bytes. - VladD