当前位置: 首页>>代码示例>>C#>>正文


C# Set.Clear方法代码示例

本文整理汇总了C#中Set.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Set.Clear方法的具体用法?C# Set.Clear怎么用?C# Set.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Set的用法示例。


在下文中一共展示了Set.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Clear_NoParams_ClearedSuccessful

        public void Clear_NoParams_ClearedSuccessful()
        {
            var set = new Set<int>(new[] { 0, 2, 4 });
            set.Clear();

            Assert.Equal(0, set.Count);
        }
开发者ID:Confirmit,项目名称:Students,代码行数:7,代码来源:SetTests.cs

示例2: Clear

 public void Clear()
 {
     Set<int> set = new Set<int>();
     set.Add(3);
     set.Clear();
     Assert.IsTrue(set.Size == 0);
 }
开发者ID:EvgeneDudkin,项目名称:Homework,代码行数:7,代码来源:SetTests.cs

示例3: ShouldClear

 public void ShouldClear()
 {
     var collection = new Set<string>();
     collection.Add("1");
     collection.Add("2");
     collection.Clear();
     Assert.AreEqual(0, collection.Count);
 }
开发者ID:p69,项目名称:magellan-framework,代码行数:8,代码来源:SetTests.cs

示例4: ClearModifiedExcepTest

        public void ClearModifiedExcepTest()
        {
            var set = new Set<int>();

            for (int i = 0; i < 1000; i++)
            {
                set.Add(i);
            }

            foreach (var item in set)
            {
                set.Clear();
            }
        }
开发者ID:Confirmit,项目名称:Students,代码行数:14,代码来源:SimpleMethTests.cs

示例5: TestIfClearLeavesAnEmptySet

        public void TestIfClearLeavesAnEmptySet()
        {
            var set = new Set<int>();
            set.Add(5);
            set.Add(7);
            set.Add(123);
            set.Add(5);
            set.Add(64);
            set.Add(1256);
            set.Add(6);
            set.Add(772);
            set.Add(6);

            set.Clear();
            Assert.AreEqual(0, set.Count);
        }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:16,代码来源:SetTests.cs

示例6: BuildMatrixAAdjInfo

        public int[][] BuildMatrixAAdjInfo(SparseMatrix A)
        {
            if (A == null)
                throw new Exception("A matrix is null");

            int[][] adj = new int[A.ColumnSize][];

            Set<int> s = new Set<int>();
            for (int i = 0; i < A.ColumnSize; i++)
            {
                s.Clear();

                List<SparseMatrix.Element> col = A.Columns[i];
                foreach (SparseMatrix.Element e in col)
                {
                    List<SparseMatrix.Element> row = A.Rows[e.i];
                    foreach (SparseMatrix.Element e2 in row)
                        s.Add(e2.j);
                }
                adj[i] = s.ToArray();
            }

            return adj;
        }
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:24,代码来源:MatrixAdjacent.cs

示例7: StatisticsCollector_MainSetMethodsCalls_ShouldGetRightStatistics

        public void StatisticsCollector_MainSetMethodsCalls_ShouldGetRightStatistics()
        {
            var statisticsCollector = new StatisticsCollector();
            var set = new Set<int>(new[] { 1, 3, 5, 7, 9 }, statisticsCollector);
            set -= 5;
            set -= 1;
            set -= 9;

            set += 15;
            set -= 15;

            set += new Set<int>(new[] { 11, 15, 17 }, statisticsCollector);
            set -= new Set<int>(new[] { 3, 11 }, statisticsCollector);

            set.Clear();

            Assert.Equal(58, statisticsCollector.Statistics);
        }
开发者ID:Confirmit,项目名称:Students,代码行数:18,代码来源:SetTests.cs

示例8: FlipTriangles

        private int FlipTriangles(List<Triad> triads, Set<int> idsToTest, Set<int> idsFlipped)
        {
            int flipped = 0;
            idsFlipped.Clear();

            foreach (int t in idsToTest)
            {
                int t2;
                if (FlipTriangle(triads, t, out t2))
                {
                    flipped += 2;
                    idsFlipped.Add(t);
                    idsFlipped.Add(t2);
                }
            }

            return flipped;
        }
开发者ID:HydAu,项目名称:FingerprintRecognition-v2.2,代码行数:18,代码来源:Triangulator.cs

示例9: ClearOnNonEmptySet

 public void ClearOnNonEmptySet() {
    var set = new Set<int>();
    set.Add(5);
    set.Add(3);
    Assert.Equals(2, set.Count);
    set.Clear();
    Assert.Equals(0, set.Count);
 }
开发者ID:ManfredLange,项目名称:csUnit,代码行数:8,代码来源:SetTests.cs

示例10: ContainsInvalidPathChars

		/// <summary>
		/// Determines if the given path contains invalid characters.
		/// </summary>
		/// <param name="p_strPath">The path to examine.</param>
		/// <returns><c>true</c> if the given path contains invalid characters;
		/// <c>false</c> otherwise.</returns>
		public static bool ContainsInvalidPathChars(string p_strPath)
		{
			if (String.IsNullOrEmpty(p_strPath))
				return false;
			Set<string> setChars = new Set<string>();

			string strPath = Path.GetDirectoryName(p_strPath);
			if (!String.IsNullOrEmpty(strPath))
			{
				foreach (char chrInvalidChar in Path.GetInvalidPathChars())
					setChars.Add("\\x" + ((Int32)chrInvalidChar).ToString("x2"));
				Regex rgxInvalidPath = new Regex("[" + String.Join("", setChars.ToArray()) + "]");
				if (rgxInvalidPath.IsMatch(strPath))
					return true;
			}

			string strFile = Path.GetFileName(p_strPath);
			if (String.IsNullOrEmpty(strPath))
				return false;
			setChars.Clear();
			foreach (char chrInvalidChar in Path.GetInvalidFileNameChars())
				setChars.Add("\\x" + ((Int32)chrInvalidChar).ToString("x2"));
			Regex rgxInvalidFile = new Regex("[" + String.Join("", setChars.ToArray()) + "]");
			return rgxInvalidFile.IsMatch(strFile);
		}
开发者ID:etinquis,项目名称:nexusmodmanager,代码行数:31,代码来源:FileUtil.cs

示例11: ReleaseSet

 internal static void ReleaseSet(Set<IEntity> value)
 {
     value.Clear();
     _setPool.Push(value);
 }
开发者ID:boo-lang,项目名称:boo,代码行数:5,代码来源:Namespaces.cs

示例12: ExtractFeatureVectors

        /// <summary>
        /// Extracts feature vectors from points in a time range.
        /// </summary>
        /// <param name="prediction">Prediction to extract vectors for.</param>
        /// <param name="training">Whether or not this is the training phase.</param>
        /// <param name="start">Start time (points without a time are always included).</param>
        /// <param name="end">End time (points without a time are always included).</param>
        /// <returns></returns>
        protected virtual IEnumerable<FeatureVectorList> ExtractFeatureVectors(Prediction prediction, bool training, DateTime start, DateTime end)
        {
            // this can be called concurrently (e.g., via the time slice model with one thread per slice), so lock on prediction to get the point objects and their vectors
            FeatureVectorList featureVectors;
            Dictionary<int, FeatureVector> pointIdFeatureVector;
            int numFeatures;
            lock (prediction)
            {
                prediction.ReleasePoints(); // so that we get new point objects each time -- their times might be modified by a sub-class (e.g., TimeSliceDCM).
                featureVectors = new FeatureVectorList(prediction.Points.Count);
                pointIdFeatureVector = new Dictionary<int, FeatureVector>(prediction.Points.Count);
                numFeatures = GetNumFeaturesExtractedFor(prediction);
                foreach (Point point in prediction.Points)
                    if (point.Time == DateTime.MinValue || (point.Time >= start && point.Time <= end))
                    {
                        point.TrueClass = point.IncidentType;
                        FeatureVector vector = new FeatureVector(point, numFeatures);
                        featureVectors.Add(vector);
                        pointIdFeatureVector.Add(point.Id, vector);
                    }
            }

            Area area = training ? prediction.Model.TrainingArea : prediction.PredictionArea;
            Set<Thread> threads = new Set<Thread>();

            #region spatial distance features
            List<Feature> spatialDistanceFeatures = Features.Where(f => f.EnumValue.Equals(FeatureType.MinimumDistanceToGeometry)).ToList();
            if (spatialDistanceFeatures.Count > 0)
            {
                Console.Out.WriteLine("Extracting spatial distance feature values");
                float distanceWhenBeyondThreshold = (float)Math.Sqrt(2.0 * Math.Pow(FeatureDistanceThreshold, 2)); // with a bounding box of FeatureDistanceThreshold around each point, the maximum distance between a point and some feature shapefile geometry would be sqrt(2*FeatureDistanceThreshold^2). That is, the feature shapefile geometry would be positioned in one of the corners of the bounding box.
                threads.Clear();
                for (int i = 0; i < Configuration.ProcessorCount; ++i)
                {
                    Thread t = new Thread(new ParameterizedThreadStart(o =>
                        {
                            int core = (int)o;
                            NpgsqlConnection threadConnection = DB.Connection.OpenConnection;
                            string pointTableName = Point.GetTableName(prediction);
                            foreach (Feature spatialDistanceFeature in spatialDistanceFeatures)
                            {
                                Shapefile shapefile = new Shapefile(int.Parse(training ? spatialDistanceFeature.TrainingResourceId : spatialDistanceFeature.PredictionResourceId));

                                NpgsqlCommand cmd = DB.Connection.NewCommand("SELECT points." + Point.Columns.Id + " as points_" + Point.Columns.Id + "," +
                                                                             "CASE WHEN COUNT(" + shapefile.GeometryTable + "." + ShapefileGeometry.Columns.Geometry + ")=0 THEN " + distanceWhenBeyondThreshold + " " +
                                                                             "ELSE min(st_distance(st_closestpoint(" + shapefile.GeometryTable + "." + ShapefileGeometry.Columns.Geometry + ",points." + Point.Columns.Location + "),points." + Point.Columns.Location + ")) " +
                                                                             "END as feature_value " +

                                                                             "FROM (SELECT *,st_expand(" + pointTableName + "." + Point.Columns.Location + "," + FeatureDistanceThreshold + ") as bounding_box " +
                                                                                   "FROM " + pointTableName + " " +
                                                                                   "WHERE " + pointTableName + "." + Point.Columns.Id + " % " + Configuration.ProcessorCount + " = " + core + " AND " +
                                                                                              "(" +
                                                                                                  pointTableName + "." + Point.Columns.Time + "='-infinity'::timestamp OR " +
                                                                                                  "(" +
                                                                                                      pointTableName + "." + Point.Columns.Time + ">[email protected]_start AND " +
                                                                                                      pointTableName + "." + Point.Columns.Time + "<[email protected]_end" +
                                                                                                  ")" +
                                                                                              ")" +
                                                                                   ") points " +

                                                                             "LEFT JOIN " + shapefile.GeometryTable + " " +

                                                                             "ON points.bounding_box && " + shapefile.GeometryTable + "." + ShapefileGeometry.Columns.Geometry + " AND " +
                                                                                 "(" +
                                                                                    shapefile.GeometryTable + "." + ShapefileGeometry.Columns.Time + "='-infinity'::timestamp OR " +
                                                                                    "(" +
                                                                                        shapefile.GeometryTable + "." + ShapefileGeometry.Columns.Time + ">[email protected]_start AND " +
                                                                                        shapefile.GeometryTable + "." + ShapefileGeometry.Columns.Time + "<[email protected]_end" +
                                                                                    ")" +
                                                                                 ")" +

                                                                             "GROUP BY points." + Point.Columns.Id, null, threadConnection);

                                DateTime spatialDistanceFeatureStart = start - spatialDistanceFeature.Parameters.GetTimeSpanValue(SpatialDistanceParameter.LagOffset);
                                DateTime spatialDistanceFeatureEnd = spatialDistanceFeatureStart + spatialDistanceFeature.Parameters.GetTimeSpanValue(SpatialDistanceParameter.LagDuration);

                                if (spatialDistanceFeatureEnd >= start)
                                    Console.Out.WriteLine("WARNING:  Spatial distance sample overlaps extraction period.");

                                if (spatialDistanceFeatureEnd < spatialDistanceFeatureStart)
                                    Console.Out.WriteLine("WARNING:  Spatial distance sample end precedes sample start.");

                                ConnectionPool.AddParameters(cmd, new Parameter("point_start", NpgsqlDbType.Timestamp, start),
                                                                  new Parameter("point_end", NpgsqlDbType.Timestamp, end),
                                                                  new Parameter("geometry_start", NpgsqlDbType.Timestamp, spatialDistanceFeatureStart),
                                                                  new Parameter("geometry_end", NpgsqlDbType.Timestamp, spatialDistanceFeatureEnd));

                                NpgsqlDataReader reader = cmd.ExecuteReader();
                                NumericFeature distanceFeature = _idNumericFeature[spatialDistanceFeature.Id];
                                while (reader.Read())
                                {
                                    FeatureVector vector;
//.........这里部分代码省略.........
开发者ID:ilMagnifico,项目名称:asymmetric-threat-tracker,代码行数:101,代码来源:FeatureBasedDCM.cs

示例13: MorphAndLookupToken

		/// <summary>
		/// Does the real work of morphing the specified word.
		/// </summary>
		/// <param name="word">The word.</param>
		/// <param name="prev">The previous word.</param>
		/// <param name="next">The next word.</param>
		/// <param name="trace">The trace.</param>
		/// <returns>All valid word synthesis records.</returns>
		ICollection<WordSynthesis> MorphAndLookupToken(string word, string prev, string next, out WordAnalysisTrace trace)
		{
			// convert the word to its phonetic shape
			PhoneticShape input = SurfaceStratum.CharacterDefinitionTable.ToPhoneticShape(word, ModeType.ANALYSIS);
			// if word contains invalid segments, the char def table will return null
			if (input == null)
			{
				MorphException me = new MorphException(MorphException.MorphErrorType.INVALID_SHAPE, this,
					string.Format(HCStrings.kstidInvalidWord, word, SurfaceStratum.CharacterDefinitionTable.ID));
				me.Data["shape"] = word;
				me.Data["charDefTable"] = SurfaceStratum.CharacterDefinitionTable.ID;
				throw me;
			}

			// create the root of the trace tree
			trace = new WordAnalysisTrace(word, input.Clone());

			Set<WordSynthesis> candidates = new Set<WordSynthesis>();
			Set<WordAnalysis> inAnalysis = new Set<WordAnalysis>();
			Set<WordAnalysis> outAnalysis = new Set<WordAnalysis>();
			inAnalysis.Add(new WordAnalysis(input, SurfaceStratum, trace));

			// Unapply rules
			for (int i = m_strata.Count - 1; i >= 0; i--)
			{
				outAnalysis.Clear();
				foreach (WordAnalysis wa in inAnalysis)
				{
					if (m_traceStrataAnalysis)
					{
						// create the stratum analysis input trace record
						StratumAnalysisTrace stratumTrace = new StratumAnalysisTrace(m_strata[i], true, wa.Clone());
						wa.CurrentTrace.AddChild(stratumTrace);
					}
					foreach (WordAnalysis outWa in m_strata[i].Unapply(wa, candidates))
					{
						// promote each analysis to the next stratum
						if (i != 0)
							outWa.Stratum = m_strata[i - 1];

						if (m_traceStrataAnalysis)
							// create the stratum analysis output trace record for the output word synthesis
							outWa.CurrentTrace.AddChild(new StratumAnalysisTrace(m_strata[i], false, outWa.Clone()));

						outAnalysis.Add(outWa);
					}
				}

				inAnalysis.Clear();
				inAnalysis.AddMany(outAnalysis);
			}

			Set<WordSynthesis> allValidSyntheses = new Set<WordSynthesis>();
			// Apply rules for each candidate entry
			foreach (WordSynthesis candidate in candidates)
			{
				Set<WordSynthesis> inSynthesis = new Set<WordSynthesis>();
				Set<WordSynthesis> outSynthesis = new Set<WordSynthesis>();
				for (int i = 0; i < m_strata.Count; i++)
				{
					// start applying at the stratum that this lex entry belongs to
					if (m_strata[i] == candidate.Root.Stratum)
						inSynthesis.Add(candidate);

					outSynthesis.Clear();
					foreach (WordSynthesis cur in inSynthesis)
					{
						if (m_traceStrataSynthesis)
						{
							// create the stratum synthesis input trace record
							StratumSynthesisTrace stratumTrace = new StratumSynthesisTrace(m_strata[i], true, cur.Clone());
							cur.CurrentTrace.AddChild(stratumTrace);
						}
						foreach (WordSynthesis outWs in m_strata[i].Apply(cur))
						{
							// promote the word synthesis to the next stratum
							if (i != m_strata.Count - 1)
								outWs.Stratum = m_strata[i + 1];

							if (m_traceStrataSynthesis)
								// create the stratum synthesis output trace record for the output analysis
								outWs.CurrentTrace.AddChild(new StratumSynthesisTrace(m_strata[i], false, outWs.Clone()));

							outSynthesis.Add(outWs);
						}
					}

					inSynthesis.Clear();
					inSynthesis.AddMany(outSynthesis);
				}

				foreach (WordSynthesis ws in outSynthesis)
//.........这里部分代码省略.........
开发者ID:sillsdev,项目名称:WorldPad,代码行数:101,代码来源:Morpher.cs

示例14: ClearTest

        public void ClearTest()
        {
            var set = new Set<int>();
            var except = true;
            var result = true;

            for (int i = 0; i < 1000; i++)
            {
                set.Add(i);
            }

            set.Clear();

            foreach (var item in set)
            {
                result = false;
                break;
            }

            Assert.AreEqual(except, result);
        }
开发者ID:Confirmit,项目名称:Students,代码行数:21,代码来源:SimpleMethTests.cs

示例15: ClearTest

 public void ClearTest()
 {
     var set = new Set<int> {1, 2, 3};
     set.Clear();
     set.ShouldBeEmpty();
 }
开发者ID:drbatty,项目名称:maths-core,代码行数:6,代码来源:SetTests.cs


注:本文中的Set.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。