本文整理汇总了C#中HashSet.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.ToDictionary方法的具体用法?C# HashSet.ToDictionary怎么用?C# HashSet.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.ToDictionary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Unify
/// <summary>
/// Returns the possible ways that a query term can unify with a program term
/// </summary>
public static IBindings Unify(this ILiteral query, ILiteral program, IBindings bindings = null)
{
var simpleUnifier = new SimpleUnifier();
var freeVariables = new HashSet<ILiteral>();
// Run the unifier
var queryFreeVars = simpleUnifier.QueryUnifier.Compile(query, bindings);
if (queryFreeVars == null) return null;
simpleUnifier.PrepareToRunProgram();
var programFreeVars = simpleUnifier.ProgramUnifier.Compile(program, bindings);
if (programFreeVars == null) return null;
freeVariables.UnionWith(queryFreeVars);
// Retrieve the unified value for the program
var result = simpleUnifier.UnifiedValue(query.UnificationKey ?? query);
// If the result was valid, return as the one value from this function
if (result != null)
{
var variableBindings = freeVariables.ToDictionary(variable => variable,
variable => simpleUnifier.UnifiedValue(variable));
return new BasicBinding(result, variableBindings);
}
else
{
return null;
}
}
示例2: Network
public Network(NetworkBuilder builder, StateOptimizer optimizer, IEnumerable<RuleBinding> rules, Dictionary<int, RuleBinding> stateRules, Dictionary<int, RuleBinding> contextRules)
{
Contract.Requires<ArgumentNullException>(builder != null, "builder");
Contract.Requires<ArgumentNullException>(optimizer != null, "optimizer");
Contract.Requires<ArgumentNullException>(rules != null, "rules");
_builder = builder;
_rules = new List<RuleBinding>(rules);
//Dictionary<int, string> stateRules = new Dictionary<int, string>();
//foreach (var rule in _rules)
//{
// stateRules[rule.StartState.Id] = rule.Name;
// stateRules[rule.EndState.Id] = rule.Name;
//}
HashSet<State> states = new HashSet<State>(ObjectReferenceEqualityComparer<State>.Default);
HashSet<Transition> transitions = new HashSet<Transition>(ObjectReferenceEqualityComparer<Transition>.Default);
foreach (var rule in _rules)
{
ExtractStatesAndTransitions(optimizer, rule, rule.StartState, states, transitions, stateRules, contextRules);
//ExtractStatesAndTransitions(rule.Name, rule.EndState, states, transitions, stateRules, contextRules);
}
_states = states.ToDictionary(i => i.Id);
_transitions = new List<Transition>(transitions);
_stateRules = stateRules;
_contextRules = contextRules;
_optimizer = optimizer;
}
示例3: DistinctOption
/// <summary>
/// Erstellt eine neue Option, die einen der angegebenen Werte aus validValues annehmen kann, mit dem angegebenen Namen in dem
/// angegebenen Abschnitt der angegebenen Einstellungsdatei.
/// [base=section, name, defaultValue, configFile]
/// </summary>
public DistinctOption(string section, string name, string defaultValue, IEnumerable<string> validValues, ConfigFile configFile)
: base(section, name, defaultValue, configFile)
{
ValidValues = new HashSet<string> (validValues);
ValidValues.Add (defaultValue);
DisplayValidValues = new Dictionary<string,string> (ValidValues.ToDictionary (x=>x,x=>x));
}
示例4: Initialize
private void Initialize()
{
_fileInfo = new HashSet<PathInfo>(
Directory.EnumerateFiles(_basePathConverted, "*", SearchOption.AllDirectories)
.Select(fileName => PathInfo.GetSubPath(_basePath, fileName)));
_fileInfoCache = _fileInfo.ToDictionary(i => GetRootPath(i), i => FileInfo.Create(GetRootPath(i)));
_directoryInfo = new HashSet<PathInfo>(
Directory.EnumerateDirectories(_basePathConverted, "*", SearchOption.AllDirectories)
.Select(fileName => PathInfo.GetSubPath(_basePath, fileName)));
}
示例5: FindPartDependencies
private Dictionary<KspPartObject, List<KspPartLinkProperty>> FindPartDependencies (KspCraftObject craft, RegexFilter filter)
{
ui.DisplayUserMessage ($"Entering craft '{craft.Name}'...");
var partLookup = new PartLookup (craft);
var dependencies = partLookup.LookupParts (filter).ToList ();
var dependentParts = new HashSet<KspPartObject> ();
Parallel.ForEach (dependencies, dependency => {
foreach (var part in partLookup.LookupSoftDependencies (dependency)) {
lock (dependentParts) {
dependentParts.Add (part);
}
}
});
ui.DisplayUserMessage ($"Found {dependentParts.Count} dependent parts");
return dependentParts.ToDictionary (part => part, part => FindPartLinks (part, dependencies));
}
示例6: Build
internal static Dictionary<string, DocumentedNamespaceTree> Build(IEnumerable<DocumentedNamespace> @namespaces)
{
var result = new HashSet<DocumentedNamespaceTree>();
foreach (var ns in namespaces)
{
result.Add(new DocumentedNamespaceTree(ns));
}
foreach (var tree in result)
{
var parts = tree.Namespace.Identity.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
var prefix = string.Join(".", parts.Take(parts.Length - 1));
foreach (var other in result)
{
if (other.Namespace.Identity == prefix)
{
other.AddChild(tree);
}
}
}
return result.ToDictionary(x => x.Namespace.Identity, x => x, StringComparer.Ordinal);
}
示例7: SynchronizeSchemasScript
public static SqlPreCommand SynchronizeSchemasScript(Replacements replacements)
{
HashSet<SchemaName> model = Schema.Current.GetDatabaseTables().Select(a => a.Name.Schema).ToHashSet();
HashSet<SchemaName> database = new HashSet<SchemaName>();
foreach (var db in model.Select(a => a.Database).Distinct())
{
using (Administrator.OverrideDatabaseInViews(db))
{
database.AddRange(
from s in Database.View<SysSchemas>()
select new SchemaName(db, s.name));
}
}
return Synchronizer.SynchronizeScript(
model.ToDictionary(a => a),
database.ToDictionary(a => a),
(_, newSN) => SqlBuilder.CreateSchema(newSN),
null,
null, Spacing.Simple);
}
示例8: GetSecondary
public Dictionary<Webpage, HashSet<string>> GetSecondary(HashSet<Webpage> webpages)
{
if (!webpages.Any())
return new Dictionary<Webpage, HashSet<string>>();
Tag tagAlias = null;
TagInfo tagInfo = null;
string typeName = webpages.First().DocumentType;
Dictionary<int, IEnumerable<string>> tagInfoDictionary = _session.QueryOver<Webpage>()
.Where(webpage => webpage.DocumentType == typeName)
.JoinAlias(webpage => webpage.Tags, () => tagAlias)
.SelectList(builder =>
builder.Select(webpage => webpage.Id).WithAlias(() => tagInfo.WebpageId)
.Select(() => tagAlias.Name).WithAlias(() => tagInfo.TagName))
.TransformUsing(Transformers.AliasToBean<TagInfo>()).List<TagInfo>()
.GroupBy(info => info.WebpageId)
.ToDictionary(infos => infos.Key, infos => infos.Select(x => x.TagName));
return webpages.ToDictionary(webpage => webpage,
webpage =>
GetSecondaryTerms(webpage,
tagInfoDictionary.ContainsKey(webpage.Id)
? tagInfoDictionary[webpage.Id]
: Enumerable.Empty<string>()).ToHashSet());
}
示例9: SynchronizeSchemasScript
public static SqlPreCommand SynchronizeSchemasScript(Replacements replacements)
{
HashSet<SchemaName> model = Schema.Current.GetDatabaseTables().Select(a => a.Name.Schema).Where(a => !SqlBuilder.SystemSchemas.Contains(a.Name)).ToHashSet();
HashSet<SchemaName> database = new HashSet<SchemaName>();
foreach (var db in Schema.Current.DatabaseNames())
{
using (Administrator.OverrideDatabaseInSysViews(db))
{
var schemaNames = Database.View<SysSchemas>().Select(s => s.name).ToList().Except(SqlBuilder.SystemSchemas);
database.AddRange(schemaNames.Select(sn => new SchemaName(db, sn)));
}
}
using (replacements.WithReplacedDatabaseName())
return Synchronizer.SynchronizeScriptReplacing(replacements, "Schemas",
model.ToDictionary(a => a.ToString()),
database.ToDictionary(a => a.ToString()),
(_, newSN) => SqlBuilder.CreateSchema(newSN),
(_, oldSN) => DropSchema(oldSN) ? SqlBuilder.DropSchema(oldSN) : null,
(_, newSN, oldSN) => newSN.Equals(oldSN) ? null :
SqlPreCommand.Combine(Spacing.Simple, SqlBuilder.DropSchema(oldSN), SqlBuilder.CreateSchema(newSN)),
Spacing.Double);
}
示例10: SubqueryRemover
// constructors
private SubqueryRemover(IEnumerable<SelectExpression> selectsToRemove)
{
_selectsToRemove = new HashSet<SelectExpression>(selectsToRemove);
_map = _selectsToRemove.ToDictionary(d => d.Alias,
d => d.Columns.ToDictionary(d2 => d2.Name, d2 => d2.Expression));
}
示例11: GetLiveStates
private HashSet<State> GetLiveStates(HashSet<State> states)
{
var dictionary = states.ToDictionary(s => s, s => new HashSet<State>());
foreach (State s in states)
{
foreach (Transition t in s.Transitions)
{
// TODO: Java code does not check for null states.
if (t.To == null)
{
continue;
}
dictionary[t.To].Add(s);
}
}
var comparer = new StateEqualityComparer();
var live = new HashSet<State>(this.GetAcceptStates(), comparer);
var worklist = new LinkedList<State>(live);
while (worklist.Count > 0)
{
State s = worklist.RemoveAndReturnFirst();
foreach (State p in dictionary[s])
{
if (!live.Contains(p))
{
live.Add(p);
worklist.AddLast(p);
}
}
}
return live;
}
示例12: Spawn
public void Spawn()
{
PreventTurrets();
TakeOutTurrets();
var units = new HashSet<Unit> { Unit.CLAW, Unit.ARCHER, Unit.HACKER, Unit.REPAIRER, Unit.TERMINATOR, Unit.TURRET };
var ourUnitCounts = units.ToDictionary(u => u, u => 0);
var theirUnitCounts = units.ToDictionary(u => u, u => 0);
droids.Where(d => units.Contains((Unit)d.Variant)).ForEach(d => { if (d.Owner == Bb.id) ourUnitCounts[(Unit)d.Variant]++; else theirUnitCounts[(Unit)d.Variant]++; });
var theirTotal = theirUnitCounts.Sum(kvp => kvp.Value);
var isSpawningTurretsSoon = Bb.TheirSpawning.ToPoints().Any(p => (Unit)Bb.TileLookup[p].VariantToAssemble == Unit.TURRET && Bb.TileLookup[p].TurnsUntilAssembled < 10);
float targetClawRatio = theirTotal == 0 ? 1.0f : 0.0f;
float targetHackerRatio = theirUnitCounts[Unit.HACKER] + theirUnitCounts[Unit.CLAW];
float targetArcherRatio = theirUnitCounts[Unit.ARCHER] + theirUnitCounts[Unit.TURRET] + (isSpawningTurretsSoon ? 5 : 0);
float targetTerminatorRatio = theirUnitCounts[Unit.ARCHER] + theirUnitCounts[Unit.TERMINATOR] + theirUnitCounts[Unit.CLAW] + theirUnitCounts[Unit.REPAIRER];
float targetRepairerRatio = theirUnitCounts[Unit.ARCHER] / 4 + theirUnitCounts[Unit.CLAW] / 4 + ourUnitCounts[Unit.TERMINATOR];
var total = targetClawRatio + targetHackerRatio + targetArcherRatio + targetTerminatorRatio + targetRepairerRatio;
targetHackerRatio /= total;
targetArcherRatio /= total;
targetTerminatorRatio /= total;
targetRepairerRatio /= total;
float unitCount = Bb.OurUnits.Count() - Bb.OurHangars.Count() - Bb.OurTurrets.Count() - Bb.OurWalls.Count() + .0001f;
int clawCount = Bb.OurClaws.Count();
int archerCount = Bb.OurArchers.Count();
int hackerCount = Bb.OurHackers.Count();
int terminatorCount = Bb.OurTerminators.Count();
int repairerCount = Bb.OurRepairers.Count();
if (CanAfford(Unit.CLAW) && clawCount / unitCount < targetClawRatio)
{
SpawnUnit(Unit.CLAW);
Bb.ReadBoard();
}
if (CanAfford(Unit.TERMINATOR) && terminatorCount / unitCount < targetTerminatorRatio)
{
SpawnUnit(Unit.TERMINATOR);
Bb.ReadBoard();
}
if (CanAfford(Unit.HACKER) && hackerCount / unitCount < targetHackerRatio)
{
SpawnUnit(Unit.HACKER);
Bb.ReadBoard();
}
if (CanAfford(Unit.ARCHER) && archerCount / unitCount < targetArcherRatio)
{
SpawnUnit(Unit.ARCHER);
Bb.ReadBoard();
}
if (CanAfford(Unit.REPAIRER) && repairerCount / unitCount < targetRepairerRatio)
{
SpawnUnit(Unit.REPAIRER);
Bb.ReadBoard();
}
}
示例13: Replace
public static String Replace(this String input, String pattern, Func<ReadOnlyDictionary<String, String>, String> replacer, RegexOptions options)
{
if (input == null) return null;
var names = new HashSet<String>();
var m_meta = Regex.Match(pattern, @"\(\?\<(?<name>.*?)\>");
for (; m_meta.Success; m_meta = m_meta.NextMatch())
{
var name = m_meta.Result("${name}");
names.Add(name);
}
return Regex.Replace(input, pattern, m => replacer(names.ToDictionary(name => name, name => m.Result("${" + name + "}")).ToReadOnly()), options);
}
示例14: GetSecondary
public Dictionary<Layout, HashSet<string>> GetSecondary(HashSet<Layout> layouts)
{
return layouts.ToDictionary(layout => layout, layout => GetSecondary(layout).ToHashSet());
}
示例15: GetSecondary
public Dictionary<MediaCategory, HashSet<string>> GetSecondary(HashSet<MediaCategory> mediaCategories)
{
return mediaCategories.ToDictionary(category => category, category => GetSecondary(category).ToHashSet());
}