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


C# HashSet.IsSupersetOf方法代码示例

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


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

示例1: Parsing_Of_Sc_Query_Output

		public void Parsing_Of_Sc_Query_Output()
		{
			string output = Resources.ScQueryOutput;
			HashSet<ServiceItem> expected = new HashSet<ServiceItem>
			{
				new ServiceItem
				{
					ServiceName = "TermService",
					DisplayName = "Terminal Services"
				},
				new ServiceItem
				{
					ServiceName = "Themes",
					DisplayName = "Themes"
				},
				new ServiceItem
				{
					ServiceName = "UNS",
					DisplayName = "Intel(R) Management and Security Application User Notification Service"
				}
			};

			HashSet<ServiceItem> actual = ServiceHelper_Accessor.ParseServicesOutput(output);

			Assert.IsTrue(expected.IsSubsetOf(actual));
			Assert.IsTrue(expected.IsSupersetOf(actual));
		}
开发者ID:penartur,项目名称:CCNet.Extensions,代码行数:27,代码来源:ServiceHelperTest.cs

示例2: Main

        static void Main(string[] args)
        {
            var ukCities = new HashSet<string>
            {
                "Ripon",
                "Manchester",
                "Sheffield",
                "Truro"
            };

            var bigUKCities = new HashSet<string>
            {
                "Sheffield",
                "Manchester"
            };

            var bigCitiesArray = new HashSet<string>
            {
                "New York",
                "Manchester",
                "Sheffield",
                "Paris"
            };

            //bool ukIsSubset = bigUKCities.IsSubsetOf(ukCities);
            bool ukIsSuperset = ukCities.IsSupersetOf(bigUKCities);
            Console.WriteLine(ukIsSuperset);

            // bool bigUKIsSubset = bigUKCities.IsSubsetOf(bigCitiesArray);
            bool bigUKIsSuperset = bigCitiesArray.IsSupersetOf(bigUKCities);
            Console.WriteLine(bigUKIsSuperset);
        }
开发者ID:johanvergeer,项目名称:ps-c-sharp-collection-fundamentals,代码行数:32,代码来源:Program.cs

示例3: TestSubSetSuperSet

		public void TestSubSetSuperSet ()
		{
			var aSet = new HashSet<int> { 1, 2 };  
			var bSet = new HashSet<int> { 1 };  
		
			Assert.IsTrue (aSet.IsSubsetOf (aSet));
			Assert.IsTrue (bSet.IsSubsetOf (aSet));

			Assert.IsTrue (bSet.IsProperSubsetOf (aSet));
			Assert.IsFalse (aSet.IsProperSubsetOf (aSet));

			Assert.IsTrue (aSet.IsSupersetOf (aSet));
			Assert.IsTrue (aSet.IsSupersetOf (bSet));

			Assert.IsTrue (aSet.IsProperSupersetOf (bSet));
			Assert.IsFalse (aSet.IsProperSupersetOf (aSet));
		}
开发者ID:caloggins,项目名称:DOT-NET-on-Linux,代码行数:17,代码来源:HashSetExampleTests.cs

示例4: GetMessages

		private IEnumerableEx<Level1ChangeMessage> GetMessages()
		{
			var types = new HashSet<Level1Fields>(Level1FieldsCtrl.SelectedFields);

			var messages = StorageRegistry
				.GetLevel1MessageStorage(SelectedSecurity, Drive, StorageFormat)
				.Load(From, To + TimeHelper.LessOneDay);

			return messages
				.Where(m => types.IsSupersetOf(m.Changes.Keys))
				.ToEx(messages.Count);
		}
开发者ID:jackman0925,项目名称:StockSharp,代码行数:12,代码来源:Level1Pane.xaml.cs

示例5: CreateInstance

        /// <summary>
        /// Gets the instance of the created command object.
        /// </summary>
        /// <param name="tokens">Command line arguments to initialize command with.</param>
        /// <exception cref="Exception{OptionsValidationExceptionArgs}">
        /// Indicates that at least one required option was not specified.
        /// </exception>
        internal object CreateInstance(IDictionary<string, OptionValue> tokens)
        {
            HashSet<string> availableOptions =
                new HashSet<string>(tokens.Select(t => t.Key.ToLowerInvariant()));

            OptionMetadata[] targetMetadata = null;

            // Find options set that matches our tokens collection.
            foreach (var usage in _metadata.Options)
            {
                HashSet<string> requiredOptions =
                    new HashSet<string>(usage.Where(o => o.Required).Select(o => o.Name.ToLowerInvariant()));
                HashSet<string> allOptions =
                    new HashSet<string>(usage.Select(o => o.Name.ToLowerInvariant()));

                if (requiredOptions.IsSubsetOf(availableOptions) &&
                    allOptions.IsSupersetOf(availableOptions))
                {
                    targetMetadata = usage;
                    break;
                }
            }

            if (null == targetMetadata)
            {
                var args = new OptionsValidationExceptionArgs("Invalid command arguments provided.");
                throw new Exception<OptionsValidationExceptionArgs>(args);
            }

            try
            {
                return CreateInstanceInternal(targetMetadata, tokens);
            }
            catch (TargetInvocationException ex)
            {
                var argumentError = ex.InnerException as ArgumentException;
                if (null == argumentError)
                    throw;

                string msg = string.Format("Invalid value for option '{0}'. {1}",
                                           argumentError.ParamName,
                                           argumentError.Message);
                var args = new OptionsValidationExceptionArgs(msg);
                throw new Exception<OptionsValidationExceptionArgs>(args);
            }
            catch (MissingMethodException)
            {
                var args = new OptionsValidationExceptionArgs("Invalid command arguments provided.");
                throw new Exception<OptionsValidationExceptionArgs>(args);
            }
        }
开发者ID:modulexcite,项目名称:WebSync,代码行数:58,代码来源:CommandBuilder.cs

示例6: Main

        static void Main()
        {
            var companyTeams = new HashSet<string>() { "Ferrari", "McLaren", "Mercedes" };
            var traditionalTeams = new HashSet<string>() { "Ferrari", "McLaren" };
            var privateTeams = new HashSet<string>() { "Red Bull", "Lotus", "Toro Rosso", "Force India", "Sauber" };

            if (privateTeams.Add("Williams"))
                WriteLine("Williams added");
            if (!companyTeams.Add("McLaren"))
                WriteLine("McLaren was already in this set");

            if (traditionalTeams.IsSubsetOf(companyTeams))
            {
                WriteLine("traditionalTeams is subset of companyTeams");
            }

            if (companyTeams.IsSupersetOf(traditionalTeams))
            {
                WriteLine("companyTeams is a superset of traditionalTeams");
            }


            traditionalTeams.Add("Williams");
            if (privateTeams.Overlaps(traditionalTeams))
            {
                WriteLine("At least one team is the same with traditional and private teams");
            }

            var allTeams = new SortedSet<string>(companyTeams);
            allTeams.UnionWith(privateTeams);
            allTeams.UnionWith(traditionalTeams);

            WriteLine();
            WriteLine("all teams");
            foreach (var team in allTeams)
            {
                WriteLine(team);
            }

            allTeams.ExceptWith(privateTeams);
            WriteLine();
            WriteLine("no private team left");
            foreach (var team in allTeams)
            {
                WriteLine(team);
            }

        }
开发者ID:ProfessionalCSharp,项目名称:ProfessionalCSharp6,代码行数:48,代码来源:Program.cs

示例7: Cozy

        public static void Cozy()
        {
            Console.WriteLine("\n-----------------------------------------------");
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
            Console.WriteLine("-----------------------------------------------");

            //HashSet<T>和List<T>差不多的,但HashSet<T>只能包含不重复的元素
            var hashSet = new HashSet<int>();

            //Add()会返回一个bool值,添加成功返回true,集合内有相同的元素,则添加失败返回false
            Console.WriteLine(hashSet.Add(1));     //output True
            Console.WriteLine(hashSet.Add(1));     //output False

            Console.WriteLine(hashSet.Add(2));
            Console.WriteLine(hashSet.Add(3));

            var array = new[] {1, 2, 3, 4, 5};


            Console.WriteLine(hashSet.IsSubsetOf(array));       //output True
            Console.WriteLine(hashSet.IsSupersetOf(array));     //output False

            //增加array集合的元素
            hashSet.UnionWith(array);

            foreach (var i in hashSet)
            {
                Console.WriteLine(i);
            }

            //移除array集合的元素
            hashSet.ExceptWith(array);

            foreach (var i in hashSet)
            {
                Console.WriteLine(i);
            }
        }
开发者ID:xxy1991,项目名称:cozy,代码行数:38,代码来源:I8Set.cs

示例8: IsScopeSatisfied

		/// <summary>
		/// Checks whether the granted scope is a superset of the required scope.
		/// </summary>
		/// <param name="requiredScope">The set of strings that the resource server demands in an access token's scope in order to complete some operation.</param>
		/// <param name="grantedScope">The set of strings that define the scope within an access token that the client is authorized to.</param>
		/// <returns><c>true</c> if <paramref name="grantedScope"/> is a superset of <paramref name="requiredScope"/> to allow the request to proceed; <c>false</c> otherwise.</returns>
		/// <remarks>
		/// The default reasonable implementation of this is:
		/// <code>
		///     return <paramref name="grantedScope"/>.IsSupersetOf(<paramref name="requiredScope"/>);
		/// </code>
		/// <para>In some advanced cases it may not be so simple.  One case is that there may be a string that aggregates the capabilities of several others
		/// in order to simplify common scenarios.  For example, the scope "ReadAll" may represent the same authorization as "ReadProfile", "ReadEmail", and 
		/// "ReadFriends".
		/// </para>
		/// <para>Great care should be taken in implementing this method as this is a critical security module for the authorization and resource servers.</para>
		/// </remarks>
		public bool IsScopeSatisfied(HashSet<string> requiredScope, HashSet<string> grantedScope) {
			Requires.NotNull(requiredScope, "requiredScope");
			Requires.NotNull(grantedScope, "grantedScope");
			return grantedScope.IsSupersetOf(requiredScope);
		}
开发者ID:437072341,项目名称:dotnetopenid,代码行数:22,代码来源:StandardScopeSatisfiedCheck.cs

示例9: VerifyStreamsForPlayback

        /// <summary>
        /// Verifies that the streams selected for playback exist in the file and are capable of being played on the service
        /// </summary>
        /// <param name="client">KStudioClient which is connected to the Kinect service</param>
        /// <param name="filePath">Path to file that will be played back</param>
        /// <param name="playbackStreams">Collection of streams which have been selected for playback</param>
        private static void VerifyStreamsForPlayback(KStudioClient client, string filePath, IEnumerable<Guid> playbackStreams)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (!client.IsServiceConnected)
            {
                throw new InvalidOperationException(Strings.ErrorNotConnected);
            }

            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            if (playbackStreams == null)
            {
                throw new ArgumentNullException("playbackStreams");
            }

            // verify stream exists in the file
            using (KStudioEventFile file = client.OpenEventFile(filePath))
            {
                HashSet<Guid> fileStreams = new HashSet<Guid>();
                foreach (KStudioEventStream stream in file.EventStreams)
                {
                    fileStreams.Add(stream.DataTypeId);
                }

                if (!fileStreams.IsSupersetOf(playbackStreams))
                {
                    Guid invalidStream = playbackStreams.First(x => !fileStreams.Contains(x));
                    throw new InvalidOperationException(string.Format(Strings.ErrorPlaybackStreamNotInFile, StreamSupport.ConvertStreamGuidToString(invalidStream)));
                }
            }

            // verify stream is supported for playback by the Kinect sensor
            foreach (Guid stream in playbackStreams)
            {
                KStudioEventStream eventStream = client.GetEventStream(stream, KStudioEventStreamSemanticIds.KinectDefaultSensorConsumer);
                if (!eventStream.IsPlaybackable)
                {
                    throw new InvalidOperationException(string.Format(Strings.ErrorPlaybackStreamNotSupported, StreamSupport.ConvertStreamGuidToString(stream)));
                }
            }
        }
开发者ID:angelaHillier,项目名称:KSUtil,代码行数:54,代码来源:Playback.cs

示例10: IsSupersetOfFailureTest

        public void IsSupersetOfFailureTest()
        {
            var set = new HashSet<int>();
            var arr = Enumerable.Range(0, 10).ToArray();
            for (int i = 0; i < 5; i++)
            {
                set.Add(i);
            }

            Assert.IsFalse(set.IsSupersetOf(arr));
        }
开发者ID:Confirmit,项目名称:Students,代码行数:11,代码来源:HashSetUnitTest.cs

示例11: IsSupersetOfTest

        public void IsSupersetOfTest()
        {
            var set = new HashSet<int>();
            var arr = Enumerable.Range(0, 10).ToArray();
            for (int i = 0; i < 50; i++)
            {
                set.Add(i -25);
            }

            Assert.IsTrue(set.IsSupersetOf(arr));
        }
开发者ID:Confirmit,项目名称:Students,代码行数:11,代码来源:HashSetUnitTest.cs

示例12: GetRouteValues

    /// <summary>
    /// 获取路由值
    /// </summary>
    /// <param name="virtualPath">当前请求的虚拟路径</param>
    /// <param name="queryString">当前请求的查询数据</param>
    /// <returns></returns>
    public IDictionary<string, string> GetRouteValues( string virtualPath, NameValueCollection queryString )
    {

      if ( virtualPath == null )
        throw new ArgumentNullException( "virtualPath" );

      if ( !VirtualPathUtility.IsAppRelative( virtualPath ) )
        throw new ArgumentException( "virtualPath 只能使用应用程序根相对路径,即以 \"~/\" 开头的路径,调用 VirtualPathUtility.ToAppRelative 方法或使用 HttpRequest.AppRelativeCurrentExecutionFilePath 属性获取", "virtualPath" );



      var queryKeySet = new HashSet<string>( _queryKeys, StringComparer.OrdinalIgnoreCase );
      var requestQueryKeySet = new HashSet<string>( queryString.AllKeys, StringComparer.OrdinalIgnoreCase );

      if ( LimitedQueries && !queryKeySet.IsSupersetOf( requestQueryKeySet ) )//如果限制了查询键并且查询键集合没有完全涵盖所有传进来的QueryString键的话,即存在有一个QueryString键不在查询键集合中,则这条规则不适用。
        return null;



      virtualPath = multipleSlashRegex.Replace( virtualPath, "/" );//将连续的/替换成单独的/
      var extensionLength = VirtualPathUtility.GetExtension( virtualPath ).Length;
      if ( extensionLength > 0 )
        virtualPath = virtualPath.Remove( virtualPath.Length - extensionLength );//去除扩展名


      virtualPath = virtualPath.Substring( 2 );
      virtualPath = VirtualPathUtility.RemoveTrailingSlash( virtualPath ) ?? "";//在虚拟路径最后移除 / ,使得 xxx/ 与 xxx 被视为同一路径。


      var pathParagraphs = virtualPath.Split( '/' );

      if ( virtualPath == "" )
        pathParagraphs = new string[0];


      if ( pathParagraphs.Length != Paragraphes.Length )//路径段长度不一致,规则不适用
        return null;


      var values = new Dictionary<string, string>( StringComparer.OrdinalIgnoreCase );



      foreach ( var pair in _staticValues )
        values.Add( pair.Key, pair.Value );

      for ( int i = 0; i < pathParagraphs.Length; i++ )
      {

        var paragraph = Paragraphes[i];

        if ( !paragraph.StartsWith( "{" ) )
        {
          if ( !pathParagraphs[i].EqualsIgnoreCase( paragraph ) )//静态路径段不符,规则不适用
            return null;
        }
        else
        {
          var name = paragraph.Substring( 1, paragraph.Length - 2 );
          values.Add( name, pathParagraphs[i] );
        }
      }



      if ( !LimitedQueries )//如果没有限制查询键,但传进来的查询键与现有路由键有任何冲突,则这条规则不适用。
      {                     //因为如果限制了查询键,则上面会确保查询键不超出限制的范围,且查询键的范围与路由键范围不可能重合(构造函数限定),也就不可能存在冲突。
        requestQueryKeySet.IntersectWith( _routeKeys );
        if ( requestQueryKeySet.Any() )
          return null;
      }


      foreach ( var key in queryString.AllKeys )
      {
        if ( key == null )
          continue;//因某些未知原因会导致 AllKeys 包含空键值。

        var v = queryString[key];
        if ( v != null )
          values.Add( key, v );
      }


      return values;
    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:92,代码来源:SimpleRouteRule.cs

示例13: IsSupersetOfEqualsSetsTest

 public void IsSupersetOfEqualsSetsTest()
 {
     var set = new HashSet<int>();
     var arr = Enumerable.Range(0, 10).ToArray();
     set.UnionWith(arr);
     Assert.IsTrue(set.IsSupersetOf(arr));
 }
开发者ID:Confirmit,项目名称:Students,代码行数:7,代码来源:HashSetUnitTest.cs

示例14: FindReverseDependencies

        /// <summary>
        /// Finds and returns all modules that could not exist without the listed modules installed, including themselves.
        /// Acts recursively.
        /// </summary>
        internal static HashSet<string> FindReverseDependencies(IEnumerable<string> modules_to_remove, IEnumerable<Module> orig_installed, IEnumerable<string> dlls)
        {
            while (true)
            {
                // Make our hypothetical install, and remove the listed modules from it.
                HashSet<Module> hypothetical = new HashSet<Module>(orig_installed); // Clone because we alter hypothetical.
                hypothetical.RemoveWhere(mod => modules_to_remove.Contains(mod.identifier));

                log.DebugFormat("Started with {0}, removing {1}, and keeping {2}; our dlls are {3}", string.Join(", ", orig_installed), string.Join(", ", modules_to_remove), string.Join(", ", hypothetical), string.Join(", ", dlls));

                // Find what would break with this configuration.
                // The Values.SelectMany() flattens our list of broken mods.
                var broken = new HashSet<string>(SanityChecker.FindUnmetDependencies(hypothetical, dlls)
                    .Values.SelectMany(x => x).Select(x => x.identifier));

                // If nothing else would break, it's just the list of modules we're removing.
                HashSet<string> to_remove = new HashSet<string>(modules_to_remove);

                if (to_remove.IsSupersetOf(broken))
                {
                    log.DebugFormat("{0} is a superset of {1}, work done", string.Join(", ", to_remove), string.Join(", ", broken));
                    return to_remove;
                }

                // Otherwise, remove our broken modules as well, and recurse.
                broken.UnionWith(to_remove);
                modules_to_remove = broken;
            }
        }
开发者ID:Gustavo6046,项目名称:CKAN_LPIP,代码行数:33,代码来源:Registry.cs

示例15: GetMaxStateId

        private int GetMaxStateId(IEnumerable<TreeRule> rules)
        {
            HashSet<Expr> states = new HashSet<Expr>();
            HashSet<Expr> botStates = new HashSet<Expr>();
            int res = -1;
            foreach (var rule in rules)
            {
                int k = tt.Z.GetNumeralInt(rule.state);
                states.Add(rule.state);
                if (k > res)
                    res = k;
                for (int i=0; i < rule.Rank; i++)
                    foreach (var s in rule.Lookahead(i))
                        botStates.Add(s);
            }
            if (!states.IsSupersetOf(botStates))
                throw new AutomataException(AutomataExceptionKind.TreeTransducer_UndefinedState);

            return res;
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:20,代码来源:RankedAlphabet.cs


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