Esempio n. 1
0
            internal Core(Func <TItem, TItem, TDistance> distance, SmallWorld <TItem, TDistance> .Parameters parameters)
            {
                Distance   = distance;
                Parameters = parameters;

                var initialSize = Math.Max(1024, parameters.InitialItemsSize);

                Nodes = new List <Node>(initialSize);
                Items = new List <TItem>(initialSize);

                switch (Parameters.NeighbourHeuristic)
                {
                case NeighbourSelectionHeuristic.SelectSimple:
                {
                    Algorithm = new Algorithms.Algorithm3 <TItem, TDistance>(this);
                    break;
                }

                case NeighbourSelectionHeuristic.SelectHeuristic:
                {
                    Algorithm = new Algorithms.Algorithm4 <TItem, TDistance>(this);
                    break;
                }
                }

                if (Parameters.EnableDistanceCacheForConstruction)
                {
                    DistanceCache = new DistanceCache <TDistance>();
                    DistanceCache.Resize(parameters.InitialDistanceCacheSize, false);
                }

                DistanceCalculationsCount = 0;
            }
            /// <summary>
            /// Initializes a new instance of the <see cref="Core"/> class.
            /// </summary>
            /// <param name="distance">The distance function in the items space.</param>
            /// <param name="parameters">The parameters of the world.</param>
            /// <param name="items">The original items.</param>
            internal Core(Func <TItem, TItem, TDistance> distance, SmallWorld <TItem, TDistance> .Parameters parameters, IReadOnlyList <TItem> items)
            {
                this.distance   = distance;
                this.Parameters = parameters;
                this.Items      = items;

                switch (this.Parameters.NeighbourHeuristic)
                {
                case SmallWorld <TItem, TDistance> .NeighbourSelectionHeuristic.SelectSimple:
                    this.Algorithm = new Node.Algorithm3 <TItem, TDistance>(this);
                    break;

                case SmallWorld <TItem, TDistance> .NeighbourSelectionHeuristic.SelectHeuristic:
                    this.Algorithm = new Node.Algorithm4 <TItem, TDistance>(this);
                    break;
                }

                if (this.Parameters.EnableDistanceCacheForConstruction)
                {
                    this.distanceCache = new DistanceCache <TDistance>(this.Items.Count);
                }

                this.distanceCacheHitCount     = 0;
                this.distanceCalculationsCount = 0;
            }