Exemplo n.º 1
0
        public void And_CombineSingleBlockBitmaps()
        {
            var bitmap = new Bitmap(50);
            var other  = new Bitmap(50);

            bitmap.Set(0);
            bitmap.Set(10);
            bitmap.Set(14);
            bitmap.Set(22);
            bitmap.Set(20);
            bitmap.Set(42);
            bitmap.Set(41);
            bitmap.Set(43);

            other.Set(42);
            other.Set(21);

            bitmap.And(other);

            Assert.AreEqual(50, bitmap.Count);

            var bits = new bool[bitmap.Count];

            bits[42] = true;

            CollectionAssert.AreEqual(bits, bitmap.ToArray());
        }
Exemplo n.º 2
0
        public void And_CombineEmptyBitmaps()
        {
            var bitmap = new Bitmap(0);
            var other  = new Bitmap(0);

            Assert.AreEqual(0, bitmap.Count);
            Assert.AreEqual(0, other.Count);

            bitmap.And(other);

            Assert.AreEqual(0, bitmap.Count);
        }
Exemplo n.º 3
0
 public void And()
 {
     using (Bitmap TestObject = new Bitmap(@"..\..\Data\Image\Lenna.jpg"))
     {
         using (Bitmap TestObject2 = new Bitmap(@"..\..\Data\Image\Image2.jpg"))
         {
             using (Bitmap Image = Assert.Do <Bitmap>(() => TestObject.And(TestObject2, @".\Testing\LennaAnd.jpg")))
             {
                 Assert.NotNull(Image);
             }
         }
     }
 }
    static public void Main(string[] args)
    {
        Storage db = StorageFactory.Instance.CreateStorage();

        db.Open("testbitmap.dbs", pagePoolSize);

        City city = (City)db.Root;

        if (city == null)
        {
            city = new City();
#if USE_GENERICS
            city.byLocation = db.CreateSpatialIndexR2 <Restaurant>();
            city.byKitchen  = db.CreateFieldIndex <string, Restaurant>("kitchen", false, true, true);
            city.byAvgPrice = db.CreateFieldIndex <int, Restaurant>("avgPrice", false, true, true);
            city.byRating   = db.CreateFieldIndex <int, Restaurant>("rating", false, true, true);
#else
            city.byLocation = db.CreateSpatialIndexR2();
            city.byKitchen  = db.CreateFieldIndex(typeof(Restaurant), "kitchen", false, true, true);
            city.byAvgPrice = db.CreateFieldIndex(typeof(Restaurant), "avgPrice", false, true, true);
            city.byRating   = db.CreateFieldIndex(typeof(Restaurant), "rating", false, true, true);
#endif
            db.Root = city;
        }
        DateTime start = DateTime.Now;
        Random   rnd   = new Random(2013);
        for (int i = 0; i < nRecords; i++)
        {
            Restaurant rest = new Restaurant();
            rest.lat      = 55 + (float)rnd.NextDouble();
            rest.lng      = 37 + (float)rnd.NextDouble();
            rest.kitchen  = kitchens[rnd.Next(kitchens.Length)];
            rest.avgPrice = rnd.Next(1000);
            rest.rating   = rnd.Next(10);
            city.byLocation.Put(new RectangleR2(rest.lat, rest.lng, rest.lat, rest.lng), rest);
            city.byKitchen.Put(rest);
            city.byAvgPrice.Put(rest);
            city.byRating.Put(rest);
        }
        db.Commit();
        Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start));

        start = DateTime.Now;
        long total = 0;
        for (int i = 0; i < nSearches; i++)
        {
            double lat       = 55 + rnd.NextDouble();
            double lng       = 37 + rnd.NextDouble();
            String kitchen   = kitchens[rnd.Next(kitchens.Length)];
            int    minPrice  = rnd.Next(1000);
            int    maxPrice  = minPrice + rnd.Next(1000);
            int    minRating = rnd.Next(10);
            Bitmap bitmap    = db.CreateBitmap(city.byKitchen.GetEnumerator(kitchen, kitchen));
            bitmap.And(db.CreateBitmap(city.byAvgPrice.GetEnumerator(minPrice, maxPrice)));
            bitmap.And(db.CreateBitmap(city.byRating.GetEnumerator(new Key(minRating), null)));
            PersistentEnumerator enumerator = (PersistentEnumerator)city.byLocation.Neighbors(lat, lng).GetEnumerator();

            int nAlternatives = 0;
            while (enumerator.MoveNext())
            {
                int oid = enumerator.CurrentOid;
                if (bitmap.Contains(oid))
                {
                    Restaurant rest = (Restaurant)db.GetObjectByOID(oid);
                    total += 1;
                    if (++nAlternatives == 10)
                    {
                        break;
                    }
                }
            }
        }
        Console.WriteLine("Elapsed time for " + nSearches + " searches of " + total + " variants among " + nRecords + " records: "
                          + (DateTime.Now - start) + " milliseconds");
        db.Close();
    }