Example #1
0
 public BTree(SnapStore store, string name, IComparer <TField> comparer)
 {
     this.fields    = Node.CreateFields(comparer, out this.countField, out this.isLeafField, out this.keyFields, out this.childFields);
     this.MinDegree = this.keyFields.Length / 2;
     Debug.Assert(1 < this.MinDegree && this.MinDegree * 2 + 1 == this.keyFields.Length && this.keyFields.Length + 1 == this.childFields.Length,
                  "Wrong field definition"
                  );
     this.table = new SnapTable <Node>(store, name, 1, this.fields, false);
     this.data  = new IntArray(store, name + "~Data~", 1);
                 #if ValidateTree
     this.Validate();
                 #endif
 }
        /// <summary>
        /// Constructor of SnapTable.
        /// </summary>
        /// <param name="store"></param>
        /// <param name="name"></param>
        /// <param name="initialSize"></param>
        /// <param name="fields"></param>
        /// <param name="isUserTable"></param>
        public SnapTable(SnapStore store, string name, int initialSize, IField <TRecord>[] fields, bool isUserTable)
        {
            if (!(0 <= initialSize && initialSize < int.MaxValue - 1))
            {
                throw new ArgumentOutOfRangeException(nameof(initialSize));
            }
            this.SnapStore = store;
            this.Name      = name;

            //this will reserve a special value to allow updating the nodes
            Log record = new Log();

            this.log.Add(ref record);

            if (0 < initialSize)
            {
                Row row = new Row();
                for (int i = 0; i < initialSize; i++)
                {
                    this.table.Add(ref row);
                }
            }

            //set initial sizes of the lists
            Snap point = new Snap()
            {
                //Version = 0,
                TableSize = initialSize,
                LogSize   = 1
            };

            this.snap.Add(ref point);

            IField <TRecord>[] list = (IField <TRecord>[])fields.Clone();
            for (int i = 0; i < list.Length; i++)
            {
                Debug.Assert(list[i].Order == 0 || list[i].Order == i);
                list[i].Order = i;
            }
            this.Fields = list;

            this.IsUserTable = isUserTable;
            if (this.IsUserTable)
            {
                this.Indexes     = new List <IIndex <TRecord> > [list.Length];
                this.ForeignKeys = new IForeignKey[list.Length];
                this.Children    = new List <IForeignKey>();
            }

            this.SnapStore.Add(this);
        }
Example #3
0
 public Unique(SnapStore store, string name, IComparer <TField> comparer, float loadFactor)
 {
     if (!(loadFactor >= 0.1f && loadFactor <= 1.0f))
     {
         throw new ArgumentOutOfRangeException("loadFactor");
     }
     this.valueField = new ValueField(comparer);
     this.table      = new SnapTable <Bucket>(store, name, Unique <TField> .MinSize,
                                              new IField <Bucket>[] { this.valueField, RowIdField.Field, HashField.Field, CollisionField.Field },
                                              false
                                              );
     // allocate 3 int values:
     // [0] - is the count of items inserted
     // [1] - is known size of the bucket store which is different from table size, as rollbacks or undo's will delete inserted rows
     // [2] - is occupancy - total number of collision bits set
     this.variables  = new IntArray(store, name + "~Variables~", 3);
     this.loadFactor = loadFactor;
 }
Example #4
0
 public Unique(SnapStore store, string name, IComparer <TField> comparer) : this(store, name, comparer, 0.75f)
 {
 }
Example #5
0
 public IntArray(SnapStore store, string name, int size)
 {
     this.table = new SnapTable <int>(store, name, size, new IField <int>[] { IntArray.Field }, false);
 }
Example #6
0
 private StoreSnapshot(SnapStore storeData)
 {
     this.SnapStore            = storeData;
     this.snapshotVersion      = this.SnapStore.CompletedVersion;
     this.SnapStore.Committed += new EventHandler(this.StoreDataCommitted);
 }