Пример #1
0
        public static SuffixArrayJsonResultParams Find(string suffix, int maxCount)
        {
            #region [.load tuple-data.]
            var tuples = _TupleData;
            if (tuples == null)
            {
                lock ( _Lock )
                {
                    tuples = _TupleData;
                    if (tuples == null)
                    {
                        {
                            tuples     = CreateTupleData();
                            _TupleData = tuples;
                        }
                        {
                            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                            GC.WaitForPendingFinalizers();
                            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                        }
                    }
                }
            }
            #endregion

            #region [.load suffix-array by tuple-data.]
            var sa = _SuffixArray;
            if (sa == null)
            {
                lock ( _Lock )
                {
                    sa = _SuffixArray;
                    if (sa == null)
                    {
                        {
                            sa           = new SuffixArray <tuple>(tuples, new tupleStringValueGetter());
                            _SuffixArray = sa;
                        }
                        {
                            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                            GC.WaitForPendingFinalizers();
                            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                        }
                    }
                }
            }
            #endregion

            #region [.find suffix in tuple-data.]
            var frs = sa.Find(suffix, maxCount, out var findTotalCount);
            #endregion

            #region commented

            /*
             #region [.sort result by CityType & StreetType.]
             * Array.Sort< find_result_t >( frs, (fr1, fr2) =>
             * {
             *  var street1 = tuples.GetStreet( fr1.ObjIndex );
             *  var street2 = tuples.GetStreet( fr2.ObjIndex );
             *
             *  var city1 = tuples.GetCityByIndex( street1.City );
             *  var city2 = tuples.GetCityByIndex( street2.City );
             *  if ( city1.CityType == CityTypeEnum.City )
             *  {
             *      if ( city2.CityType == CityTypeEnum.City )
             *      {
             #region [.MOSCOW & ST_PETERBURG to up.]
             *          var sct1 = GetSpecialCityType( city1.City );
             *          var sct2 = GetSpecialCityType( city2.City );
             *
             *          if ( sct1 == SpecialCityType.Moscow )
             *          {
             *              if ( sct2 != SpecialCityType.Any )
             *                  return (fr1.SuffixIndex - fr2.SuffixIndex);
             *              return (-1);
             *          }
             *          if ( sct2 == SpecialCityType.Moscow )
             *          {
             *              if ( sct1 != SpecialCityType.Any )
             *                  return (fr1.SuffixIndex - fr2.SuffixIndex);
             *              return (1);
             *          }
             *          if ( sct1 == SpecialCityType.StPeteburg )
             *          {
             *              return (-1);
             *          }
             *          if ( sct2 == SpecialCityType.StPeteburg )
             *          {
             *              return (1);
             *          }
             #endregion
             *
             *          var d = string.Compare( city1.City, city2.City, true );
             *          if ( d == 0 )
             *              return (fr1.SuffixIndex - fr2.SuffixIndex);
             *          return (d);
             *      }
             *      return (-1);
             *  }
             *  else
             *  if ( city2.CityType == CityTypeEnum.City )
             *  {
             *      return (1);
             *  }
             *
             *  if ( street1.StreetType == (int) CityTypeEnum.Street )
             *  {
             *      if ( street2.StreetType == (int) CityTypeEnum.Street )
             *      {
             *          var d = string.Compare( street1.Street, street2.Street, true );
             *          if ( d == 0 )
             *              return (fr1.SuffixIndex - fr2.SuffixIndex);
             *          return (d);
             *      }
             *      return (-1);
             *  }
             *  else
             *  if ( street2.StreetType == (int) CityTypeEnum.Street )
             *  {
             *      return (1);
             *  }
             *  return (0);
             * });
             #endregion
             */

            #endregion

            #region [.result.]
            var p = new SuffixArrayJsonResultParams()
            {
                suffix         = suffix,
                maxCount       = maxCount,
                findTotalCount = findTotalCount,
                frs            = frs,
                tuples         = tuples,
            };
            return(p);

            #endregion
        }
Пример #2
0
 public static void ToJson(this HttpResponse response, SuffixArrayJsonResultParams p)
 {
     response.ToJson(new SuffixArrayJsonResult(p));
 }