Set() public method

public Set ( int index, bool val ) : void
index int
val bool
return void
Esempio n. 1
0
        public void SetDuplicate(int bitmaprecno, int record)
        {
            WAHBitArray ba = null;

            ba = GetBitmap(bitmaprecno);

            ba.Set(record, true);
        }
Esempio n. 2
0
 public void Set(object key, int recnum)
 {
     lock (_lock)
         if (key != null)
         {
             _bits.Set(recnum, (bool)key);
         }
 }
Esempio n. 3
0
        public void SetDuplicate(int bitmaprecno, int record)
        {
            using (new L(this))
            {
                WAHBitArray ba = null;

                ba = internalGetBitmap(bitmaprecno); //GetBitmap(bitmaprecno);

                ba.Set(record, true);
            }
        }
Esempio n. 4
0
 internal void FreeBlocks(List <int> list)
 {
     list.ForEach(x => _freeList.Set(x, true));
 }
Esempio n. 5
0
 public void Set(object key, int recnum)
 {
     _bits.Set(recnum, (bool)key);
 }
Esempio n. 6
0
        private void RebuildDataFiles()
        {
            MGIndex <string> keys = null;

            try
            {
                // remove old free list
                if (File.Exists(_Path + "data.bmp"))
                {
                    File.Delete(_Path + "data.bmp");
                }

                _datastore = new StorageFileHF(_Path + "data.mghf", Global.HighFrequencyKVDiskBlockSize);
                _BlockSize = _datastore.GetBlockSize();
                if (File.Exists(_Path + "keys.idx"))
                {
                    _log.Debug("removing old keys index");
                    foreach (var f in Directory.GetFiles(_Path, "keys.*"))
                    {
                        File.Delete(f);
                    }
                }

                keys = new MGIndex <string>(_Path, "keys.idx", 255, /*Global.PageItemCount,*/ false);

                WAHBitArray visited = new WAHBitArray();

                int c = _datastore.NumberofBlocks();

                for (int i = 0; i < c; i++) // go through blocks
                {
                    if (visited.Get(i))
                    {
                        continue;
                    }
                    byte[] b    = _datastore.ReadBlockBytes(i, _blockheader.Length + 255);
                    int    bnum = Helper.ToInt32(b, 0);
                    if (bnum > 0) // check if a start block
                    {
                        visited.Set(i, true);
                        _datastore.FreeBlock(i); // mark as free
                        continue;
                    }

                    AllocationBlock ab = new AllocationBlock();
                    // start block found
                    int blocknumexpected = 0;

                    int             next     = ParseBlockHeader(ab, b, blocknumexpected);
                    int             last     = 0;
                    bool            freelast = false;
                    AllocationBlock old      = null;

                    if (keys.Get(ab.key, out last))
                    {
                        old      = this.FillAllocationBlock(last);
                        freelast = true;
                    }
                    blocknumexpected++;
                    bool failed = false;
                    if (ab.deleteKey == false)
                    {
                        while (next > 0) // read the blocks
                        {
                            ab.Blocks.Add(next);
                            b    = _datastore.ReadBlockBytes(next, _blockheader.Length + ab.keylen);
                            next = ParseBlockHeader(ab, b, blocknumexpected);
                            if (next == -1) // non matching block
                            {
                                failed = true;
                                break;
                            }
                            blocknumexpected++;
                        }
                    }
                    else
                    {
                        failed = true;
                        keys.RemoveKey(ab.key);
                    }
                    // new data ok
                    if (failed == false)
                    {
                        keys.Set(ab.key, ab.blocknumber); // valid block found
                        if (freelast)                     // free the old blocks
                        {
                            _datastore.FreeBlocks(old.Blocks);
                        }
                    }

                    visited.Set(i, true);
                }

                // all ok delete temp.$ file
                if (File.Exists(_Path + _dirtyFilename))
                {
                    File.Delete(_Path + _dirtyFilename);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
            finally
            {
                _log.Debug("Shutting down files and index");
                _datastore.Shutdown();
                keys.SaveIndex();
                keys.Shutdown();
            }
        }
Esempio n. 7
0
        private void RebuildDataFiles()
        {
            MGIndex<string> keys = null;
            try
            {
                // remove old free list
                if (File.Exists(_Path + "data.bmp"))
                    File.Delete(_Path + "data.bmp");

                _datastore = new StorageFileHF(_Path + "data.mghf", Global.HighFrequencyKVDiskBlockSize);
                _BlockSize = _datastore.GetBlockSize();
                if (File.Exists(_Path + "keys.idx"))
                {
                    _log.Debug("removing old keys index");
                    foreach (var f in Directory.GetFiles(_Path, "keys.*"))
                        File.Delete(f);
                }

                keys = new MGIndex<string>(_Path, "keys.idx", 255, Global.PageItemCount, false);

                WAHBitArray visited = new WAHBitArray();

                int c = _datastore.NumberofBlocks();

                for (int i = 0; i < c; i++) // go through blocks
                {
                    if (visited.Get(i))
                        continue;
                    byte[] b = _datastore.ReadBlockBytes(i, _blockheader.Length + 255);
                    int bnum = Helper.ToInt32(b, 0);
                    if (bnum > 0) // check if a start block
                    {
                        visited.Set(i, true);
                        _datastore.FreeBlock(i); // mark as free
                        continue;
                    }

                    AllocationBlock ab = new AllocationBlock();
                    // start block found
                    int blocknumexpected = 0;

                    int next = ParseBlockHeader(ab, b, blocknumexpected);
                    int last = 0;
                    bool freelast = false;
                    AllocationBlock old = null;

                    if (keys.Get(ab.key, out last))
                    {
                        old = this.FillAllocationBlock(last);
                        freelast = true;
                    }
                    blocknumexpected++;
                    bool failed = false;
                    if (ab.deleteKey == false)
                    {
                        while (next > 0) // read the blocks
                        {
                            ab.Blocks.Add(next);
                            b = _datastore.ReadBlockBytes(next, _blockheader.Length + ab.keylen);
                            next = ParseBlockHeader(ab, b, blocknumexpected);
                            if (next == -1) // non matching block
                            {
                                failed = true;
                                break;
                            }
                            blocknumexpected++;
                        }
                    }
                    else
                    {
                        failed = true;
                        keys.RemoveKey(ab.key);
                    }
                    // new data ok
                    if (failed == false)
                    {
                        keys.Set(ab.key, ab.blocknumber);// valid block found
                        if (freelast)// free the old blocks
                            _datastore.FreeBlocks(old.Blocks);
                    }

                    visited.Set(i, true);
                }

                // all ok delete temp.$ file
                if (File.Exists(_Path + _dirtyFilename))
                    File.Delete(_Path + _dirtyFilename);
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
            finally
            {
                _log.Debug("Shutting down files and index");
                _datastore.Shutdown();
                keys.SaveIndex();
                keys.Shutdown();
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            int count = 100;

            Global.useSortedList = false;
            Dictionary <long, bool> list = new Dictionary <long, bool>();
            var r = new Random();

            for (int i = 0; i < count; i++)
            {
                var cc = r.Next(1000 * 1000 * 1);// + 1000*1000;
                if (list.ContainsKey(cc) == false)
                {
                    list.Add(cc, true);
                }
            }
            Console.WriteLine("count = " + count);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            MGRB a = new MGRB();

            foreach (var l in list)
            {
                a.Set(l.Key, true);
            }
            sw.Stop();
            Console.WriteLine("mgrb set time : " + sw.ElapsedMilliseconds);

            sw.Reset();
            sw.Start();
            RaptorDB.WAHBitArray w = new RaptorDB.WAHBitArray();
            foreach (var l in list)
            {
                w.Set((int)l.Key, true);
            }
            sw.Stop();
            Console.WriteLine("wah set time : " + sw.ElapsedMilliseconds);


            var ok = true;

            foreach (var k in a.GetBitIndexes())
            {
                if (a.Get(k) == false)
                {
                    ok = false;
                }
            }

            a.Optimize();
            var c = a.CountOnes();

            Console.WriteLine("max list = " + list.Keys.Max());
            Console.WriteLine("max bm = " + a.Length);
            Console.WriteLine("list count = " + list.Count);
            Console.WriteLine("bm count = " + c);
            Console.WriteLine(" ok = " + ok);

            if (ok == false || list.Count != c)
            {
                throw new Exception();
            }

            if (list.Keys.Max() != a.Length)
            {
                throw new Exception();
            }

            var x = a.AndNot(new MGRB());

            x.Optimize();
            c = x.CountOnes();

            if (list.Count != c)
            {
                throw new Exception();
            }

            var y = new MGRB();
            var z = new MGRB();

            foreach (var l in list)
            {
                y.Set(l.Key, true);
                z.Set(l.Key + 1000000, true);
            }
            var zz = y.Or(z);

            c = zz.CountOnes();
            if (y.CountOnes() * 2 != c)
            {
                throw new Exception();
            }

            var zn = zz.Not();

            zn.Optimize();
            var iii = zn.CountOnes();

            var o = zz.Serialize();

            var s = fastJSON.JSON.ToNiceJSON(o, new fastJSON.JSONParameters {
                UseExtensions = false
            });

            var mmm = new MGRB();

            mmm.Deserialize(o);

            c = zz.AndNot(mmm).CountOnes();
        }