本文整理汇总了C#中HashSet.Add方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.Add方法的具体用法?C# HashSet.Add怎么用?C# HashSet.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFullSort
internal IEnumerable<SortingInfo> GetFullSort() {
var memo = new HashSet<string>();
var result = new List<SortingInfo>();
if(HasGroups) {
foreach(var g in Group) {
if(memo.Contains(g.Selector))
continue;
memo.Add(g.Selector);
result.Add(g);
}
}
if(HasSort) {
foreach(var s in Sort) {
if(memo.Contains(s.Selector))
continue;
memo.Add(s.Selector);
result.Add(s);
}
}
IEnumerable<string> requiredSort = new string[0];
if(HasDefaultSort)
requiredSort = requiredSort.Concat(new[] { DefaultSort });
if(HasPrimaryKey)
requiredSort = requiredSort.Concat(PrimaryKey);
return Utils.AddRequiredSort(result, requiredSort);
}
示例2: GetReachableNodes
/** Returns all nodes reachable from the seed node.
* This function performs a BFS (breadth-first-search) or flood fill of the graph and returns all nodes which can be reached from
* the seed node. In almost all cases this will be identical to returning all nodes which have the same area as the seed node.
* In the editor areas are displayed as different colors of the nodes.
* The only case where it will not be so is when there is a one way path from some part of the area to the seed node
* but no path from the seed node to that part of the graph.
*
* The returned list is sorted by node distance from the seed node
* i.e distance is measured in the number of nodes the shortest path from \a seed to that node would pass through.
* Note that the distance measurement does not take heuristics, penalties or tag penalties.
*
* Depending on the number of reachable nodes, this function can take quite some time to calculate
* so don't use it too often or it might affect the framerate of your game.
*
* \param seed The node to start the search from
* \param tagMask Optional mask for tags. This is a bitmask.
*
* \returns A List<Node> containing all nodes reachable from the seed node.
* For better memory management the returned list should be pooled, see Pathfinding.Util.ListPool
*/
public static List<GraphNode> GetReachableNodes (GraphNode seed, int tagMask = -1) {
var stack = StackPool<GraphNode>.Claim ();
var list = ListPool<GraphNode>.Claim ();
/** \todo Pool */
var map = new HashSet<GraphNode>();
GraphNodeDelegate callback;
if (tagMask == -1) {
callback = delegate (GraphNode node) {
if (node.Walkable && map.Add (node)) {
list.Add (node);
stack.Push (node);
}
};
} else {
callback = delegate (GraphNode node) {
if (node.Walkable && ((tagMask >> (int)node.Tag) & 0x1) != 0 && map.Add (node)) {
list.Add (node);
stack.Push (node);
}
};
}
callback (seed);
while (stack.Count > 0) {
stack.Pop ().GetConnections (callback);
}
StackPool<GraphNode>.Release (stack);
return list;
}
示例3: AddNewErrors
public int AddNewErrors(IVsEnumExternalErrors pErrors)
{
var projectErrors = new HashSet<DiagnosticData>();
var documentErrorsMap = new Dictionary<DocumentId, HashSet<DiagnosticData>>();
var errors = new ExternalError[1];
uint fetched;
while (pErrors.Next(1, errors, out fetched) == VSConstants.S_OK && fetched == 1)
{
var error = errors[0];
DiagnosticData diagnostic;
if (error.bstrFileName != null)
{
diagnostic = CreateDocumentDiagnosticItem(error);
if (diagnostic != null)
{
var diagnostics = documentErrorsMap.GetOrAdd(diagnostic.DocumentId, _ => new HashSet<DiagnosticData>());
diagnostics.Add(diagnostic);
continue;
}
projectErrors.Add(CreateProjectDiagnosticItem(error));
}
else
{
projectErrors.Add(CreateProjectDiagnosticItem(error));
}
}
_diagnosticProvider.AddNewErrors(_projectId, projectErrors, documentErrorsMap);
return VSConstants.S_OK;
}
示例4: PopulateTypeList
private void PopulateTypeList(ITypeDescriptorContext context)
{
_typeList = new HashSet<string>();
if (context != null)
{
var propertyDescriptor = context.Instance as EFPropertyDescriptor;
if (propertyDescriptor != null
&& propertyDescriptor.TypedEFElement != null)
{
var artifact = propertyDescriptor.TypedEFElement.Artifact;
Debug.Assert(artifact != null, "Unable to find artifact.");
if (artifact != null)
{
foreach (var primType in ModelHelper.AllPrimitiveTypesSorted(artifact.SchemaVersion))
{
_typeList.Add(primType);
}
}
var conceptualModel =
(ConceptualEntityModel)propertyDescriptor.TypedEFElement.GetParentOfType(typeof(ConceptualEntityModel));
Debug.Assert(conceptualModel != null, "Unable to find conceptual model.");
if (conceptualModel != null)
{
foreach (var enumType in conceptualModel.EnumTypes())
{
_typeList.Add(enumType.NormalizedNameExternal);
}
}
}
}
}
示例5: actions
public HashSet<Action> actions(System.Object state)
{
EightPuzzleBoard board = (EightPuzzleBoard)state;
HashSet<Action> actions = new HashSet<Action>();
if (board.canMoveGap(EightPuzzleBoard.UP))
{
actions.Add(EightPuzzleBoard.UP);
}
if (board.canMoveGap(EightPuzzleBoard.DOWN))
{
actions.Add(EightPuzzleBoard.DOWN);
}
if (board.canMoveGap(EightPuzzleBoard.LEFT))
{
actions.Add(EightPuzzleBoard.LEFT);
}
if (board.canMoveGap(EightPuzzleBoard.RIGHT))
{
actions.Add(EightPuzzleBoard.RIGHT);
}
return actions;
}
示例6: DiagnosticAnalyzerAllInOne
public void DiagnosticAnalyzerAllInOne()
{
var source = TestResource.AllInOneCSharpCode;
// AllInOneCSharpCode has no properties with initializers or named types with primary constructors.
var symbolKindsWithNoCodeBlocks = new HashSet<SymbolKind>();
symbolKindsWithNoCodeBlocks.Add(SymbolKind.Property);
symbolKindsWithNoCodeBlocks.Add(SymbolKind.NamedType);
var syntaxKindsMissing = new HashSet<SyntaxKind>();
// AllInOneCSharpCode has no deconstruction or declaration expression
syntaxKindsMissing.Add(SyntaxKind.SingleVariableDesignation);
syntaxKindsMissing.Add(SyntaxKind.ParenthesizedVariableDesignation);
syntaxKindsMissing.Add(SyntaxKind.ForEachVariableStatement);
syntaxKindsMissing.Add(SyntaxKind.DeclarationExpression);
syntaxKindsMissing.Add(SyntaxKind.DiscardDesignation);
var analyzer = new CSharpTrackingDiagnosticAnalyzer();
CreateCompilationWithMscorlib45(source).VerifyAnalyzerDiagnostics(new[] { analyzer });
analyzer.VerifyAllAnalyzerMembersWereCalled();
analyzer.VerifyAnalyzeSymbolCalledForAllSymbolKinds();
analyzer.VerifyAnalyzeNodeCalledForAllSyntaxKinds(syntaxKindsMissing);
analyzer.VerifyOnCodeBlockCalledForAllSymbolAndMethodKinds(symbolKindsWithNoCodeBlocks);
}
示例7: WriteDirectory
/// <summary>
/// Writes index files into the specified directory.
/// </summary>
/// <param name="indexDirectory">The directory into which the index files should be written.</param>
/// <param name="recordMapper">The mapper for the records.</param>
/// <param param name="records">The records which should be written.</param>
public void WriteDirectory(DirectoryInfo indexDirectory, IRecordMapper<string> recordMapper, IEnumerable<IReferenceRecord> records)
{
if (!indexDirectory.Exists)
{
indexDirectory.Create();
}
var directoryNames = new HashSet<string>();
foreach (var directory in indexDirectory.GetDirectories())
{
if (!directoryNames.Contains(directory.Name))
{
directoryNames.Add(directory.Name);
}
}
foreach (var record in records)
{
var directoryName = recordMapper.Map(record);
if (!directoryNames.Contains(directoryName))
{
indexDirectory.CreateSubdirectory(directoryName);
directoryNames.Add(directoryName);
}
// Write index files into the index directory
}
}
示例8: ConnectedComponents
public List<Graph> ConnectedComponents()
{
List<Graph> ret = new List<Graph>();
HashSet<int> visited = new HashSet<int>();
Queue<int> queue = new Queue<int>();
ForEachVertex((v) =>
{
if (!visited.Contains(v))
{
Graph g = new Graph();
queue.Enqueue(v);
visited.Add(v);
while (queue.Count != 0)
{
int u = queue.Dequeue();
g.storage[u] = storage[u];
ForEachNeighbor(u, (w) =>
{
if (!visited.Contains(w))
{
queue.Enqueue(w);
visited.Add(w);
}
});
}
ret.Add(g);
}
});
return ret;
}
示例9: ChooseProxyMethodsFrom
/// <summary>
/// Determines which methods can be proxied from
/// the given <paramref name="baseType"/> and <paramref name="baseInterfaces"/>.
/// </summary>
/// <remarks>By default, only public virtual methods will be proxied.</remarks>
/// <param name="baseType">The base class of the proxy type currently being generated.</param>
/// <param name="baseInterfaces">The list of interfaces that the proxy must implement.</param>
/// <returns>A list of <see cref="MethodInfo"/> objects that can be proxied.</returns>
public IEnumerable<MethodInfo> ChooseProxyMethodsFrom(Type baseType, IEnumerable<Type> baseInterfaces)
{
var results = new HashSet<MethodInfo>();
var baseMethods = from method in baseType.GetMethods()
where method.IsVirtual && !method.IsFinal && !method.IsPrivate
select method;
// Add the virtual methods defined
// in the base type
foreach (var method in baseMethods)
{
if (!results.Contains(method))
results.Add(method);
}
var interfaceMethods = from currentInterface in baseInterfaces
from method in currentInterface.GetMethods()
where method.IsPublic && method.IsVirtual &&
!method.IsFinal && !results.Contains(method)
select method;
// Add the virtual methods defined
// in the interface types
foreach (var method in interfaceMethods)
{
results.Add(method);
}
return results;
}
示例10: Game1
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
// make set for keeping track of which cards have already been drawn (and therefore shouldn't be drawn again),
// also add our three special 'cards' so we don't get those from our random card generator
usedCards = new HashSet<Point>();
usedCards.Add(CARD_BACKING);
usedCards.Add(CARD_FOUNDATION);
usedCards.Add(CARD_DECK_END);
rng = new Random(System.DateTime.Now.Millisecond); // new seed every time we run (likely)
toDraw = new List<DrawInfo>();
// Generate the various positioning numbers:
DISTANCE_BETWEEN_ITEMS = (Window.ClientBounds.Width - (7 * CARD_WIDTH)) / 8;
DECK_POSITION = new Vector2(DISTANCE_BETWEEN_ITEMS, DISTANCE_BETWEEN_ITEMS);
DISCARD_POSITION = new Vector2(DECK_POSITION.X + CARD_WIDTH + DISTANCE_BETWEEN_ITEMS, DECK_POSITION.Y);
FOUNDATION_POSITIONS = new Vector2[4];
FOUNDATION_POSITIONS[0] = new Vector2(DISCARD_POSITION.X + CARD_WIDTH * 2 + DISTANCE_BETWEEN_ITEMS * 2, DECK_POSITION.Y);
for (int i = 1; i < FOUNDATION_POSITIONS.Length; i++) {
FOUNDATION_POSITIONS[i].X = FOUNDATION_POSITIONS[i - 1].X + CARD_WIDTH + DISTANCE_BETWEEN_ITEMS;
FOUNDATION_POSITIONS[i].Y = FOUNDATION_POSITIONS[i - 1].Y;
}
TABLEAU_POSITIONS = new Vector2[7];
TABLEAU_POSITIONS[0] = new Vector2(DECK_POSITION.X, DECK_POSITION.Y + CARD_HEIGHT + DISTANCE_BETWEEN_ITEMS * 3);
for (int i = 1; i < TABLEAU_POSITIONS.Length; i++) {
TABLEAU_POSITIONS[i].X = TABLEAU_POSITIONS[i - 1].X + CARD_WIDTH + DISTANCE_BETWEEN_ITEMS;
TABLEAU_POSITIONS[i].Y = TABLEAU_POSITIONS[i - 1].Y;
}
}
示例11: CreateExternalBundlesFromReferences
protected IEnumerable<Bundle> CreateExternalBundlesFromReferences(IEnumerable<Bundle> bundlesArray, CassetteSettings settings)
{
var referencesAlreadyCreated = new HashSet<string>();
foreach (var bundle in bundlesArray)
{
foreach (var reference in bundle.References)
{
if (reference.IsUrl() == false) continue;
if (referencesAlreadyCreated.Contains(reference)) continue;
var externalBundle = CreateExternalBundle(reference, bundle, settings);
referencesAlreadyCreated.Add(externalBundle.Path);
yield return externalBundle;
}
foreach (var asset in bundle.Assets)
{
foreach (var assetReference in asset.References)
{
if (assetReference.Type != AssetReferenceType.Url ||
referencesAlreadyCreated.Contains(assetReference.Path)) continue;
var externalBundle = CreateExternalBundle(assetReference.Path, bundle, settings);
referencesAlreadyCreated.Add(externalBundle.Path);
yield return externalBundle;
}
}
}
}
示例12: FindPermutations
public static HashSet<string> FindPermutations(string word)
{
if (word.Length == 2)
{
char[] _c = word.ToCharArray();
string s = new string(new char[] { _c[1], _c[0] });
return new HashSet<string> { word, s };
}
var _result = new HashSet<string>();
var _subsetPermutations = FindPermutations(word.Substring(1));
char _firstChar = word[0];
foreach (string s in _subsetPermutations)
{
string _temp = _firstChar.ToString() + s;
_result.Add(_temp);
char[] _chars = _temp.ToCharArray();
for (int i = 0; i < _temp.Length - 1; i++)
{
char t = _chars[i];
_chars[i] = _chars[i + 1];
_chars[i + 1] = t;
string s2 = new string(_chars);
_result.Add(s2);
}
}
return _result;
}
示例13: AddAdditionalSpelling
private void AddAdditionalSpelling(string identifier, object value)
{
// Had a mapping for it. It will either map to a single
// spelling, or to a set of spellings.
if (value is string)
{
if (!string.Equals(identifier, value as string, StringComparison.Ordinal))
{
// We now have two spellings. Create a collection for
// that and map the name to it.
var set = new HashSet<string>();
set.Add(identifier);
set.Add((string)value);
map[identifier] = set;
}
}
else
{
// We have multiple spellings already.
var spellings = value as HashSet<string>;
// Note: the set will prevent duplicates.
spellings.Add(identifier);
}
}
示例14: AddDuplicateItemTest
public void AddDuplicateItemTest()
{
HashSet<string> names = new HashSet<string>();
names.Add("Pesho");
names.Add("Pesho");
}
示例15: BFS
private static void BFS(ref string[,] arr, AllowedCoords start)
{
var set = new Set<int>();
var queue = new Queue<AllowedCoords>();
var set = new HashSet<AllowedCoords>();
int depth = 1;
queue.Enqueue(start);
set.Add(start);
while (queue.Count > 0)
{
var coords = queue.Dequeue();
if (arr[coords.Row, coords.Col] == "0")
{
arr[coords.Row, coords.Col] = depth.ToString();
}
var neighbors = coords.GetAdjacent();
for (int i = 0; i < neighbors.Count; i++)
{
var coordinates = neighbors[i];
if (!set.Contains(coordinates))
{
depth++;
set.Add(coordinates);
queue.Enqueue(coordinates);
}
}
}
}