示例#1
0
        static void Main()
        {
            Random rng = new Random();

            for (int trial = 0; trial < 10000; ++trial)
            {
                bool failed = false;

                BetterBitArray ba = new BetterBitArray(rng.Next(100000) + 1);

                Hashtable true_hash = new Hashtable();
                int       N         = 1 + rng.Next(10000);
                for (int k = 0; k < N; ++k)
                {
                    int j = rng.Next(ba.Count);
                    ba [j]        = true;
                    true_hash [j] = true;
                }

                int i = 0;
                while (i < ba.Count)
                {
                    i = ba.GetNextTrueIndex(i);
                    if (i < ba.Count)
                    {
                        if (true_hash.Contains(i))
                        {
                            true_hash.Remove(i);
                        }
                        else
                        {
                            Console.WriteLine("Spurious true at {0}", i);
                            failed = true;
                        }
                    }

                    ++i;
                }

                if (true_hash.Count > 0)
                {
                    Console.WriteLine("Missed some trues:");
                    foreach (int k in true_hash.Values)
                    {
                        Console.WriteLine("  {0}", k);
                    }
                    failed = true;
                }

                Console.WriteLine("Trial #{0}: {1}", trial + 1,
                                  failed ? "FAILED" : "ok");
            }
        }
示例#2
0
 public int GetNextNonZeroIndex(int start)
 {
     if (start >= length)
     {
         return(length);
     }
     if (start < 0)
     {
         start = 0;
     }
     return(bit_array.GetNextTrueIndex(start * bits_per_int) / bits_per_int);
 }
示例#3
0
        public void Incr(BetterBitArray bit_array)
        {
            if (bit_array.Length != length)
            {
                throw new Exception("Incr BetterBitArray has wrong length!");
            }

            int i = 0;

            while (i < length)
            {
                i = bit_array.GetNextTrueIndex(i);
                if (i >= length)
                {
                    break;
                }
                Set(i, Get(i) + 1);
                ++i;
            }
        }
示例#4
0
		public void Incr (BetterBitArray bit_array)
		{
			if (bit_array.Length != length)
				throw new Exception ("Incr BetterBitArray has wrong length!");

			int i = 0;
			while (i < length) {
				i = bit_array.GetNextTrueIndex (i);
				if (i >= length)
					break;
				Set (i, Get (i) + 1);
				++i;
			}
		}
示例#5
0
		// Returns a list of all files and directories in dir
		static ICollection GetAllItemsInDirectory (DirectoryInfo dir)
		{
			// form the query
			string parent_uri_str = PathToUri (dir.FullName).ToString ();

			// Instead of taking the painfull way of using BeagleAnalyzer, lets just add the prefix manually
			// LuceneCommon thinks exposing secret property type encoding is bad, I think so too... except for now
			string key = "prop:k:" + Property.ParentDirUriPropKey;
			//Logger.Log.Debug ("Querying for {0}={1}", parent_uri_str, key);
			LNS.Query query = new LNS.TermQuery (new Term (key, parent_uri_str));

			// do the search
			LNS.IndexSearcher searcher;
			searcher = LuceneCommon.GetSearcher (driver.PrimaryStore);

			BetterBitArray matches;
			matches = new BetterBitArray (searcher.MaxDoc ());

			BitArrayHitCollector collector;
			collector = new BitArrayHitCollector (matches);

			searcher.Search (query, null, collector);
			
			// Finally we pull all of the matching documents,
			// convert them to Dirent, and store them in a list.

			ArrayList match_list = new ArrayList ();
			int i = 0;
			while (i < matches.Count) {
				
				i = matches.GetNextTrueIndex (i);
				if (i >= matches.Count)
					break;

				Document doc;
				doc = searcher.Doc (i);

				Dirent info;
				info = DocumentToDirent (doc);

				match_list.Add (info);

				++i;
			}

			LuceneCommon.ReleaseSearcher (searcher);
			//Logger.Log.Debug ("Found {0} items in {1}", match_list.Count, dir.FullName);

			return match_list;
		}
示例#6
0
		static void Main ()
		{
			Random rng = new Random ();
			
			for (int trial = 0; trial < 10000; ++trial) {

				bool failed = false;
				
				BetterBitArray ba = new BetterBitArray (rng.Next (100000) + 1);
				
				Hashtable true_hash = new Hashtable ();
				int N = 1 + rng.Next (10000);
				for (int k = 0; k < N; ++k) {
					int j = rng.Next (ba.Count);
					ba [j] = true;
					true_hash [j] = true;
				}

				int i = 0;
				while (i < ba.Count) {
					i = ba.GetNextTrueIndex (i);
					if (i < ba.Count) {
						if (true_hash.Contains (i)) {
							true_hash.Remove (i);
						} else {
							Console.WriteLine ("Spurious true at {0}", i);
							failed = true;
						}
					}
					
					++i;
				}

				if (true_hash.Count > 0) {
					Console.WriteLine ("Missed some trues:");
					foreach (int k in true_hash.Values)
						Console.WriteLine ("  {0}", k);
					failed = true;
				}

				Console.WriteLine ("Trial #{0}: {1}", trial+1,
						   failed ? "FAILED" : "ok");
			}
		}
		// Return all directories with name
		public ICollection GetAllDirectoryNameInfo (string name)
		{
			// First we assemble a query to find all of the directories.
			string field_name;
			field_name = PropertyToFieldName (PropertyType.Keyword,
							  Property.IsDirectoryPropKey);
			LNS.Query isdir_query = new LNS.TermQuery (new Term (field_name, "true"));

			LNS.Query query = null;

			if (name == null) {
				query = isdir_query;
			} else {
				string dirname_field;
				dirname_field = PropertyToFieldName (PropertyType.Text,
								     Property.TextFilenamePropKey);
				LNS.Query dirname_query;
				dirname_query = LuceneCommon.StringToQuery (dirname_field, name, null);
				LNS.BooleanQuery bool_query = new LNS.BooleanQuery ();
				bool_query.Add (isdir_query, LNS.BooleanClause.Occur.MUST);
				bool_query.Add (dirname_query, LNS.BooleanClause.Occur.MUST);

				query = bool_query;
			}

			// Then we actually run the query
			LNS.IndexSearcher searcher;
			//searcher = new LNS.IndexSearcher (SecondaryStore);
			searcher = LuceneCommon.GetSearcher (SecondaryStore);

			BetterBitArray matches;
			matches = new BetterBitArray (searcher.MaxDoc ());

			BitArrayHitCollector collector;
			collector = new BitArrayHitCollector (matches);

			searcher.Search (query, null, collector);
			
			// Finally we pull all of the matching documents,
			// convert them to NameInfo, and store them in a list.

			ArrayList match_list = new ArrayList ();
			int i = 0;
			while (i < matches.Count) {
				
				i = matches.GetNextTrueIndex (i);
				if (i >= matches.Count)
					break;

				Document doc;
				doc = searcher.Doc (i, fields_nameinfo);

				NameInfo info;
				info = DocumentToNameInfo (doc);

				match_list.Add (info);

				++i;
			}

			LuceneCommon.ReleaseSearcher (searcher);

			return match_list;
		}