Ejemplo n.º 1
0
        // adds a place (given by index) found via binary search to the list, and adds places above and below it
        // in the sort order as long as they match
        bool AddIndexAndVicinity(int nPos, IndexedTiledPlaceNameSet itps, string strSearch, bool bPartialAllowed)
        {
            PlaceItem pi = itps.wplIndex.GetPlaceItem(nPos); // get the place from the index

            // add item via delegate to avoid MT issues
            listViewResults.Invoke(listViewResults.addPlaceDelegate, new object[] { pi });

            // instantiate our special comparer - will compare search string to a place given by index - this is the same one
            // we're using in the binary search
            WplIndex.IndexEntryToStringComparer cmp = new WplIndex.IndexEntryToStringComparer(itps.wplIndex, bPartialAllowed);
            int nBelow = nPos - 1; // left neighbour in search order (if any)
            int nAbove = nPos + 1; // right neighbour in search order (if any)

            bool bFoundOne;        // keeps track if "expansion mechanism" still found something

            do
            {
                // return false if stop requested or too many results
                if (CheckStopRequested() || CheckMaxResults())
                {
                    return(false);
                }

                bFoundOne = false;
                if (itps.wplIndex.IsValidIndex(nBelow) && cmp.Compare(nBelow, strSearch) == 0)
                {                                            // left neighbour index valid and matched
                    pi = itps.wplIndex.GetPlaceItem(nBelow); // get the data

                    // add item via delegate to avoid MT issues
                    listViewResults.Invoke(listViewResults.addPlaceDelegate, new object[] { pi });

                    --nBelow; // expand to the left
                    bFoundOne = true;
                }

                if (itps.wplIndex.IsValidIndex(nAbove) && cmp.Compare(nAbove, strSearch) == 0)
                {                                            // right neighbour index valid and matched
                    pi = itps.wplIndex.GetPlaceItem(nAbove); // get the data

                    // add item via delegate to avoid MT issues
                    listViewResults.Invoke(listViewResults.addPlaceDelegate, new object[] { pi });

                    ++nAbove; // expand to the left
                    bFoundOne = true;
                }
            } while(bFoundOne); // keep expanding until nothing new on both sides

            return(true);       // keep searching
        }
Ejemplo n.º 2
0
      // adds a place (given by index) found via binary search to the list, and adds places above and below it
      // in the sort order as long as they match
      bool AddIndexAndVicinity(int nPos, IndexedTiledPlaceNameSet itps, string strSearch, bool bPartialAllowed) 
      { 
         PlaceItem pi = itps.wplIndex.GetPlaceItem(nPos); // get the place from the index

         // add item via delegate to avoid MT issues
         listViewResults.Invoke(listViewResults.addPlaceDelegate, new object[] { pi });

         // instantiate our special comparer - will compare search string to a place given by index - this is the same one
         // we're using in the binary search
         WplIndex.IndexEntryToStringComparer cmp = new WplIndex.IndexEntryToStringComparer(itps.wplIndex, bPartialAllowed);
         int nBelow = nPos-1; // left neighbour in search order (if any)
         int nAbove = nPos+1; // right neighbour in search order (if any)

         bool bFoundOne; // keeps track if "expansion mechanism" still found something
         do 
         {
            // return false if stop requested or too many results
            if(CheckStopRequested() || CheckMaxResults()) 
            {
               return false;
            }

            bFoundOne = false;
            if(itps.wplIndex.IsValidIndex(nBelow) && cmp.Compare(nBelow, strSearch) == 0) 
            {  // left neighbour index valid and matched 
               pi = itps.wplIndex.GetPlaceItem(nBelow); // get the data

               // add item via delegate to avoid MT issues
               listViewResults.Invoke(listViewResults.addPlaceDelegate, new object[] { pi });

               --nBelow; // expand to the left
               bFoundOne = true;
            }

            if(itps.wplIndex.IsValidIndex(nAbove) && cmp.Compare(nAbove, strSearch) == 0) 
            { // right neighbour index valid and matched 
               pi = itps.wplIndex.GetPlaceItem(nAbove); // get the data

               // add item via delegate to avoid MT issues
               listViewResults.Invoke(listViewResults.addPlaceDelegate, new object[] { pi });

               ++nAbove; // expand to the left
               bFoundOne = true;
            }
         } while(bFoundOne); // keep expanding until nothing new on both sides

         return true; // keep searching
      }