本文整理汇总了C#中HashSet.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.CopyTo方法的具体用法?C# HashSet.CopyTo怎么用?C# HashSet.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.CopyTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderScene
public OutputData RenderScene(Scene scene)
{
ISet<Task<RenderData>> results = new HashSet<Task<RenderData>>();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
Vector3f rayDirection = renderManager.CalculateEyeRayDirection(x, y);
Vector3f rayStart = new Vector3f(x, y, 0.0f);
results.Add(taskFactory.StartNew(() => CastEyeRay(new Ray(rayStart, rayDirection), scene)));
}
}
Task<RenderData>[] resultsArray = new Task<RenderData>[results.Count];
results.CopyTo(resultsArray, 0);
Task.WaitAll(resultsArray);
BasicOutputConverter coverter = new BasicOutputConverter(1, width, height);
RenderData[] finalData = new RenderData[resultsArray.Length];
for (int i = 0; i < finalData.Length; i++)
{
finalData[i] = resultsArray[i].Result;
}
return coverter.DoConversion(finalData);
}
示例2: Add
private List<Line> lines = new List<Line>(); // The lines contain info about all blocks from bottom to top.
#endregion Fields
#region Methods
/// <summary>
/// Add the chip blocks to grid.
/// </summary>
/// <param name='toAdd'>
/// The chip is will be added.
/// </param>
public void Add(Chip toAdd)
{
int lineIndex, blockIndex;
Vector3 blockPos;
Line tempLine;
HashSet<Line> affectedLines=new HashSet<Line>();
foreach(Transform blockTrans in toAdd.blocks){
blockPos=transform.TransformPoint(blockTrans.position);
lineIndex=Mathf.RoundToInt(blockPos.y);
if(lineIndex>=lines.Count){
for(int i=lineIndex-lines.Count; i>=0; i--){
tempLine=Instantiate(lineEtalon)as Line;
tempLine.transform.SetParent(transform);
tempLine.transform.rotation=Quaternion.identity;
tempLine.transform.localPosition=new Vector3(0f, lines.Count, 0f);
lines.Add(tempLine);
}
}
tempLine=lines[lineIndex];
affectedLines.Add(tempLine);
blockIndex=Mathf.RoundToInt(blockPos.x);
tempLine.blocks[blockIndex]=blockTrans;
blockTrans.SetParent(tempLine.transform);
}
//remove chip
toAdd.blocks.Clear();
Destroy(toAdd.gameObject);
//check lines for remove
Line[] checkList=new Line[affectedLines.Count];
affectedLines.CopyTo(checkList);
RemoveFilledLines(checkList);
}
示例3: Intersection
public int[] Intersection(int[] nums1, int[] nums2)
{
int[] intersectArray = new int[0];
if (nums1.Length == 0 || nums2.Length == 0)
{
return intersectArray;
}
foreach(int i in nums1)
{
if (!valueSet.Contains(i))
{
valueSet.Add(i);
}
}
HashSet<int> intersectSet = new HashSet<int>();
foreach(int j in nums2)
{
if (valueSet.Contains(j))
{
intersectSet.Add(j);
}
}
intersectArray = new int[intersectSet.Count];
intersectSet.CopyTo(intersectArray);
return intersectArray;
}
示例4: GetAuditSaveRequest
protected AuditSaveRequest GetAuditSaveRequest(ISaveRequestHandler handler)
{
var auditFields = new HashSet<Field>();
var flag = handler.IsCreate ? FieldFlags.Insertable : FieldFlags.Updatable;
foreach (var field in handler.Row.GetFields())
if (field.Flags.HasFlag(flag))
auditFields.Add(field);
Field[] array = new Field[auditFields.Count];
auditFields.CopyTo(array);
var auditRequest = new AuditSaveRequest(handler.Row.Table, (IIdRow)handler.Old, (IIdRow)handler.Row, array);
var parentIdRow = handler.Row as IParentIdRow;
if (parentIdRow != null)
{
var parentIdField = (Field)parentIdRow.ParentIdField;
if (!parentIdField.ForeignTable.IsTrimmedEmpty())
{
auditRequest.ParentTypeId = parentIdField.ForeignTable;
auditRequest.OldParentId = handler.IsCreate ? null : parentIdRow.ParentIdField[handler.Old];
auditRequest.NewParentId = parentIdRow.ParentIdField[handler.Row];
}
}
return auditRequest;
}
示例5: ForceDirectedLayout
/// <summary>
/// Initializes this force-directed layout. Assumes that graph has some
/// reasonable initial node positions.
/// </summary>
/// <param name="graph">The graph to layout.</param>
/// <param name="start_node">The node to start layout from.</param>
public ForceDirectedLayout(IReadOnlyGraph<FDLNode, FDLEdge> graph, FDLNode start_node)
{
if (graph == null)
throw new ArgumentNullException("graph");
if (start_node == null)
throw new ArgumentNullException("start_node");
if (!graph.ContainsNode(start_node))
throw new ArgumentException("start_node must be in this graph");
//initialize nodes array to only the reachable nodes
ArrayList n = new ArrayList(graph.NodeCount);
Algorithms.Algorithms.BreadthFirstSearch(graph, start_node, null, delegate(FDLNode node){
n.Add(node);
});
nodes = new FDLNode[n.Count];
n.CopyTo(nodes);
new_positions = new MutablePoint[nodes.Length];
accels = new double[nodes.Length];
//summarize constraints
HashSet<FDLEdge> h = new HashSet<FDLEdge>();
for (int i = 0; i < nodes.Length; i++)
{
foreach (FDLEdge edge in nodes[i].OutEdges)
{
DefaultEdge reverse = edge.Target.GetEdgeTo(edge.Source);
if(h.Contains(edge) || (reverse != null && h.Contains(reverse)))
continue;
h.Add(edge);
}
}
constraints = new FDLEdge[h.Count];
h.CopyTo(constraints);
}
示例6: RemoveDuplicates
public static string[] RemoveDuplicates(string[] s)
{
HashSet<string> set = new HashSet<string>(s);
string[] result = new string[set.Count];
set.CopyTo(result);
return result;
}
示例7: Union
public IGeometry Union()
{
PointLocator locater = new PointLocator();
// use a set to eliminate duplicates, as required for union
var exteriorCoords = new HashSet<Coordinate>();
foreach (IPoint point in PointExtracter.GetPoints(_pointGeom))
{
Coordinate coord = point.Coordinate;
Location loc = locater.Locate(coord, _otherGeom);
if (loc == Location.Exterior)
{
exteriorCoords.Add(coord);
}
}
// if no points are in exterior, return the other geom
if (exteriorCoords.Count == 0)
{
return _otherGeom;
}
// make a puntal geometry of appropriate size
var exteriorCoordsArray = new Coordinate[exteriorCoords.Count];
exteriorCoords.CopyTo(exteriorCoordsArray, 0);
Array.Sort(exteriorCoordsArray);
ICoordinateSequence coords = _geomFact.CoordinateSequenceFactory.Create(exteriorCoordsArray);
IGeometry ptComp = coords.Count == 1 ? (IGeometry)_geomFact.CreatePoint(coords.GetCoordinate(0)) : _geomFact.CreateMultiPoint(coords);
// add point component to the other geometry
return GeometryCombiner.Combine(ptComp, _otherGeom);
}
示例8: foreach
void IInitializable.Initialize()
{
// parse resource metadata annotation.
HashSet<string> metafileExts = new HashSet<string>();
char[] sep = { ';' };
foreach (ChildInfo chInfo in m_schemaLoader.GetRootElements())
{
DomNodeType domtype = chInfo.Type;
IEnumerable<XmlNode> annotations = domtype.GetTag<IEnumerable<XmlNode>>();
if (annotations == null)
continue;
foreach (XmlElement annot in annotations)
{
if (annot.LocalName != "ResourceMetadata")
continue;
string metaExt = annot.GetAttribute("metadataFileExt").ToLower();
metafileExts.Add(metaExt);
string[] resExts = annot.GetAttribute("resourceFileExts").ToLower().Split(sep, StringSplitOptions.RemoveEmptyEntries);
foreach (string ext in resExts)
{
ResourceMetadataInfo metadataInfo
= new ResourceMetadataInfo(chInfo, metaExt);
m_extMap.Add(ext, metadataInfo);
}
}
}
m_metadataFileExts = new string[metafileExts.Count];
metafileExts.CopyTo(m_metadataFileExts);
}
示例9: Init
public static void Init()
{
if ( !PluginSettings.Instance.PlayerBlockEnforcementEnabled )
return;
if (_init)
return;
_init = true;
MyEntities.OnEntityAdd += MyEntities_OnEntityAdd;
HashSet<MyEntity> allEntities = new HashSet<MyEntity>();
Wrapper.GameAction( () => allEntities = MyEntities.GetEntities() );
MyEntity[] entitiesCopy = new MyEntity[allEntities.Count];
allEntities.CopyTo( entitiesCopy );
Parallel.ForEach( entitiesCopy, ( entity ) =>
{
var grid = entity as MyCubeGrid;
if ( grid == null )
return;
InitGrid( grid );
} );
Essentials.Log.Info( "Initialized player block enforcement." );
ProcessEnforcement();
}
示例10: Filter
protected virtual void Filter(HashSet<Tile> tiles)
{
Tile[] array = new Tile[tiles.Count];
tiles.CopyTo(array);
for (int i = array.Length - 1; i >= 0; --i)
if (array[i].unit != null)
tiles.Remove(array[i]);
}
示例11: Test_CopyTo
public void Test_CopyTo()
{
hs = new HashSet<int>();
hs.Add(1); hs.Add(2); hs.Add(3);
int[] mass = { 1, 2, 3 };
int[] mass1 = new int[3];
hs.CopyTo(mass1);
Assert.That(mass1, Is.EqualTo(mass));
}
示例12: CopyTo_Array_Test2
public static void CopyTo_Array_Test2()
{
HashSet<int> hashSet = new HashSet<int>(new int[] { 1, 2, 3, 4, 5, 6, 7 });
int[] array = new int[] { -1, -2, -3, -4, -5, -6, -7, -8, -9 };
hashSet.CopyTo(array);
HashSet<int> hashSet2 = new HashSet<int>(array);
HashSetTestSupport<int>.VerifyHashSet(hashSet, new int[] { 1, 2, 3, 4, 5, 6, 7 }, EqualityComparer<int>.Default);
HashSetTestSupport<int>.VerifyHashSet(hashSet2, new int[] { 1, 2, 3, 4, 5, 6, 7, -8, -9 }, EqualityComparer<int>.Default);
}
示例13: ReadBeats
private uint[] ReadBeats(StoryBeat[] beats)
{
HashSet<uint> seenIds = new HashSet<uint>();
foreach (StoryBeat beat in beats)
foreach (StoryEvent evt in beat.Events)
foreach (uint id in evt.Participants)
seenIds.Add(id);
uint[] result = new uint[seenIds.Count];
seenIds.CopyTo(result);
return result;
}
示例14: CopyTo_Array_Exceptions
public static void CopyTo_Array_Exceptions()
{
//Test 1: Array is null
HashSet<int> hashSet = new HashSet<int>(new int[] { 1, 2, 3, 4, 5, 6, 7 });
int[] array = null;
Assert.Throws<ArgumentNullException>(() => hashSet.CopyTo(array)); //"Expected ArgumentNullException"
//Test 2: Array is one smaller than set size
hashSet = new HashSet<int>(new int[] { 1, 2, 3, 4, 5, 6, 7 });
array = new int[6];
Assert.Throws<ArgumentException>(() => hashSet.CopyTo(array)); //"Expected ArgumentException"
}
示例15: setIntTuplesWithSwapsAndSignChange
public void setIntTuplesWithSwapsAndSignChange(IntTuple[] inputIntTuples, IntTupleEqualityComparer comparer)
{
HashSet<IntTuple> container = new HashSet<IntTuple>(comparer);
foreach (var intTuple in inputIntTuples)
{
container.Add(intTuple);
addOppositeElements(container, intTuple);
addSwapElements(container);
}
this.intTuples = new IntTuple[container.Count];
container.CopyTo(this.intTuples);
}