public SuperSlowUncompressedBitmap(CompressedBitmap bitmap)
        {
            int p    = 0;
            var bits = new bool[bitmap.Bounds.Highest + 32];

            foreach (var word in bitmap)
            {
                if (word.IsLiteral)
                {
                    var w = word.Literal;
                    int n = 31;
                    while (n-- > 0)
                    {
                        if ((w & 1) == 1)
                        {
                            bits[p] = true;
                        }
                        ++p;
                        w >>= 1;
                    }
                }
                else if (word.FillBit == 1)
                {
                    int n = word.FillCount;
                }
            }
            this.Bits       = bits;
            this.LowestBit  = bitmap.Bounds.Lowest;
            this.HighestBit = bitmap.Bounds.Highest;
        }
		public CompressedBitmapBuilder(CompressedBitmap bitmap)
		{
			if (bitmap == null) throw new ArgumentNullException("bitmap");
			if ((bitmap.Data.Count & 3) != 0) throw new ArgumentException("Bitmap's underlying buffer size should be a multiple of 4 bytes", "bitmap");

			if (bitmap.Count == 0)
			{
				m_words = s_emptyArray;
				var range = BitRange.Empty;
				m_lowest = range.Lowest;
				m_highest = range.Highest;
			}
			else
			{
				m_words = DecodeWords(bitmap.Data, bitmap.Count, bitmap.Bounds);
				m_size = bitmap.Count;

				var bounds = bitmap.Bounds;
				m_lowest = bounds.Lowest;
				m_highest = bounds.Highest;
			}
		}
Exemple #3
0
        public void Test_Merging_Multiple_Bitmaps()
        {
            var dataSet = new List <Character>()
            {
                new Character {
                    Id = 1, Name = "Spike Spiegel", Gender = "Male", Job = "Bounty_Hunter", Born = new DateTime(2044, 6, 26), Dead = true                           /* bang! */
                },
                new Character {
                    Id = 2, Name = "Jet Black", Gender = "Male", Job = "Bounty_Hunter", Born = new DateTime(2035, 12, 13)
                },
                new Character {
                    Id = 3, Name = "Faye Valentine", Gender = "Female", Job = "Bounty_Hunter", Born = new DateTime(1994, 8, 14)
                },
                new Character {
                    Id = 4, Name = "Edward Wong Hau Pepelu Tivruski IV", Gender = "Female", Job = "Hacker", Born = new DateTime(2058, 1, 1)
                },
                new Character {
                    Id = 5, Name = "Ein", Gender = "Male", Job = "Dog"
                },
                new Character {
                    Id = 6, Name = "Vicious", Gender = "Male", Job = "Vilain", Dead = true
                },
                new Character {
                    Id = 7, Name = "Julia", Gender = "Female", Job = "Damsel_In_Distress", Dead = true                             /* It's all a dream */
                },
                new Character {
                    Id = 8, Name = "Victoria Tepsichore", Gender = "Female", Job = "Space_Trucker"
                },
                new Character {
                    Id = 9, Name = "Punch", Gender = "Male", Job = "TV_Host"
                },
                new Character {
                    Id = 10, Name = "Judy", Gender = "Female", Job = "TV_Host"
                },
            };

            // poor man's in memory database
            var database       = new Dictionary <int, Character>();
            var indexByGender  = new MemoryIndex <string>(StringComparer.OrdinalIgnoreCase);
            var indexByJob     = new MemoryIndex <string>(StringComparer.OrdinalIgnoreCase);
            var indexOfTheDead = new MemoryIndex <bool>();

            // simulate building the indexes one document at a time
            var indexers = new[]
            {
                MakeInserter <Character, string>(indexByGender, (doc) => doc.Id, (doc) => doc.Gender),
                MakeInserter <Character, string>(indexByJob, (doc) => doc.Id, (doc) => doc.Job),
                MakeInserter <Character, bool>(indexOfTheDead, (doc) => doc.Id, (doc) => doc.Dead),
            };

            Console.WriteLine("Inserting into database...");
            foreach (var character in dataSet)
            {
                database[character.Id] = character;
                foreach (var indexer in indexers)
                {
                    indexer(character);
                }
            }

            // dump the indexes
            Console.WriteLine();
            DumpIndex("Genders", indexByGender, (s, _) => s);

            Console.WriteLine();
            DumpIndex("Jobs", indexByJob, (s, _) => s);

            Console.WriteLine();
            DumpIndex("DeadOrAlive", indexOfTheDead, (s, _) => s);

            // Où sont les femmes ?
            Console.WriteLine();
            Console.WriteLine("indexByGender.Lookup('Female')");
            CompressedBitmap females = indexByGender.Lookup("Female");

            Assert.That(females, Is.Not.Null);
            Console.WriteLine("=> {0}", females.Dump());
            DumpIndexQueryResult(database, females);

            // R.I.P
            Console.WriteLine();
            Console.WriteLine("indexOfTheDead.Lookup(dead: true)");
            CompressedBitmap deadPeople = indexOfTheDead.Lookup(true);

            Assert.That(deadPeople, Is.Not.Null);
            Console.WriteLine("=> {0}", deadPeople.Dump());
            DumpIndexQueryResult(database, deadPeople);

            // combination of both
            Console.WriteLine();
            Console.WriteLine("indexByGender.Lookup('Female') AND indexOfTheDead.Lookup(dead: true)");
            var julia = WordAlignHybridEncoder.And(females, deadPeople);

            Console.WriteLine("=> {0}", julia.Dump());
            DumpIndexQueryResult(database, julia);

            // the crew
            Console.WriteLine();
            Console.WriteLine("indexByJob.Lookup('Bounty_Hunter' OR 'Hacker' OR 'Dog')");
            var bmps = new[] { "Bounty_Hunter", "Hacker", "Dog" }.Select(job => indexByJob.Lookup(job)).ToList();
            CompressedBitmap crew = null;

            foreach (var bmp in bmps)
            {
                if (crew == null)
                {
                    crew = bmp;
                }
                else
                {
                    crew = WordAlignHybridEncoder.Or(crew, bmp);
                }
            }
            crew = crew ?? CompressedBitmap.Empty;
            Console.WriteLine("=> {0}", crew.Dump());
            DumpIndexQueryResult(database, crew);
        }
Exemple #4
0
        private static List <Character> DumpIndexQueryResult(Dictionary <int, Character> characters, CompressedBitmap bitmap)
        {
            var results = new List <Character>();

            foreach (var docId in bitmap.GetView())
            {
                Character charac;
                Assert.That(characters.TryGetValue(docId, out charac), Is.True);

                results.Add(charac);
                Console.WriteLine("- {0}: {1} {2}{3}", docId, charac.Name, charac.Gender == "Male" ? "\u2642" : charac.Gender == "Female" ? "\u2640" : charac.Gender, charac.Dead ? " (\u271D)" : "");
            }
            return(results);
        }
        private static List <Character> DumpIndexQueryResult(Dictionary <int, Character> characters, CompressedBitmap bitmap)
        {
            var results = new List <Character>();

            foreach (var docId in bitmap.GetView())
            {
                Assert.That(characters.TryGetValue(docId, out Character character), Is.True);

                results.Add(character);
                Log($"- {docId}: {character.Name} {(character.Gender == "Male" ? "\u2642" : character.Gender == "Female" ? "\u2640" : character.Gender)}{(character.Dead ? " (\u271D)" : "")}");
            }
            return(results);
        }