Here are the examples of the csharp api System.Collections.Generic.HashSet.Add(int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1034 Examples
19
Source : WavePropagator.cs
with MIT License
from BorisTheBrave
with MIT License
from BorisTheBrave
public ITopoArray<ISet<int>> ToTopoArraySets()
{
return TopoArray.CreateByIndex(index =>
{
var hs = new HashSet<int>();
for (var pattern = 0; pattern < patternCount; pattern++)
{
if (wave.Get(index, pattern))
{
hs.Add(pattern);
}
}
return (ISet<int>)(hs);
}, topology);
}
19
Source : SeparationConstraint.cs
with MIT License
from BorisTheBrave
with MIT License
from BorisTheBrave
public void VisitNearby(int index, bool undo)
{
// Dijkstra's with fixed weights is just a queue
var queue = new Queue<(int, int)>();
var visited = new HashSet<int>();
void Visit(int i2, int dist)
{
if (visited.Add(i2))
{
queue.Enqueue((i2, dist));
if (undo)
{
NewlyVisited.Remove(i2);
}
else
{
if (dist != 0)
{
NewlyVisited.Add(i2);
}
}
}
}
Visit(index, 0);
while (queue.Count > 0)
{
var (i, dist) = queue.Dequeue();
if (dist < MinDistance - 1)
{
for (var dir = 0; dir < Topology.DirectionsCount; dir++)
{
if (Topology.TryMove(i, (Direction)dir, out var i2))
{
Visit(i2, dist + 1);
}
}
}
}
}
19
Source : AdjacentModel.cs
with MIT License
from BorisTheBrave
with MIT License
from BorisTheBrave
public void AddAdjacency(Tile src, Tile dest, Direction d)
{
var id = directions.Inverse(d);
var srcPattern = GetPattern(src);
var destPattern = GetPattern(dest);
propagator[srcPattern][(int)d].Add(destPattern);
propagator[destPattern][(int)id].Add(srcPattern);
}
19
Source : AdjacentModel.cs
with MIT License
from BorisTheBrave
with MIT License
from BorisTheBrave
public void AddSample(ITopoArray<Tile> sample)
{
var topology = sample.Topology.AsGridTopology();
SetDirections(topology.Directions);
var width = topology.Width;
var height = topology.Height;
var depth = topology.Depth;
var directionCount = topology.Directions.Count;
for (var z = 0; z < depth; z++)
{
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
var index = topology.GetIndex(x, y, z);
if (!topology.ContainsIndex(index))
continue;
// Find the pattern and update the frequency
var pattern = GetPattern(sample.Get(x, y, z));
frequencies[pattern] += 1;
// Update propagator
for (var d = 0; d < directionCount; d++)
{
int x2, y2, z2;
if (topology.TryMove(x, y, z, (Direction)d, out x2, out y2, out z2))
{
var pattern2 = GetPattern(sample.Get(x2, y2, z2));
propagator[pattern][d].Add(pattern2);
}
}
}
}
}
}
19
Source : GraphAdjacentModel.cs
with MIT License
from BorisTheBrave
with MIT License
from BorisTheBrave
public void AddAdjacency(Tile src, Tile dest, EdgeLabel edgeLabel)
{
var s = GetPattern(src);
var d = GetPattern(dest);
propagator[s][(int)edgeLabel].Add(d);
}
19
Source : OverlappingModel.cs
with MIT License
from BorisTheBrave
with MIT License
from BorisTheBrave
private void Build()
{
if (propagator != null)
return;
// Update the model based on the collected data
var directions = sampleTopologyDirections;
// Collect all the pattern edges
var patternIndicesByEdge = new Dictionary<Direction, Dictionary<PatternArray, int[]>>();
var edgesByPatternIndex = new Dictionary<(Direction, int), PatternArray>();
for (var d = 0; d < directions.Count; d++)
{
var dx = directions.DX[d];
var dy = directions.DY[d];
var dz = directions.DZ[d];
var edges = new Dictionary<PatternArray, HashSet<int>>(new PatternArrayComparer());
for (var p = 0; p < patternArrays.Count; p++)
{
var edge = Overlappingreplacedysis.PatternEdge(patternArrays[p], dx, dy, dz);
if (!edges.TryGetValue(edge, out var l))
{
l = edges[edge] = new HashSet<int>();
}
l.Add(p);
edgesByPatternIndex[((Direction)d, p)] = edge;
}
patternIndicesByEdge[(Direction)d] = edges
.ToDictionary(
x => x.Key,
x => x.Value.OrderBy(y => y).ToArray(),
new PatternArrayComparer());
}
// Setup propagator
var empty = new int[0];
propagator = new List<int[][]>(patternArrays.Count);
for (var p = 0; p < patternArrays.Count; p++)
{
propagator.Add(new int[directions.Count][]);
for (var d = 0; d < directions.Count; d++)
{
var dir = (Direction)d;
var invDir = directions.Inverse(dir);
var edge = edgesByPatternIndex[(dir, p)];
if (patternIndicesByEdge[invDir].TryGetValue(edge, out var otherPatterns))
{
propagator[p][d] = otherPatterns;
}
else
{
propagator[p][d] = empty;
}
}
}
patternsToTiles = patternArrays
.Select((x, i) => new KeyValuePair<int, Tile>(i, x.Values[0, 0, 0]))
.ToDictionary(x => x.Key, x => x.Value);
tilesToPatterns = patternsToTiles.ToLookup(x => x.Value, x => x.Key);
}
19
Source : DirtyIndexPicker.cs
with MIT License
from BorisTheBrave
with MIT License
from BorisTheBrave
public void DoBan(int index, int pattern)
{
var clean = cleanPatterns.Get(index);
if (clean == pattern)
dirtyIndices.Add(index);
}
19
Source : BpViewModel.cs
with MIT License
from Bphots
with MIT License
from Bphots
public void Handle(ItemSelectedMessage message)
{
try
{
if (message.ItemInfo == null)
{
if (IsAutoMode || BpStatus.CurrentStep <= 0)
return;
if (BpStatus.StepSelectedIndex.Any())
{
foreach (var i in _listBpSteps[BpStatus.CurrentStep])
{
var vm = HeroSelectorViewModels.First(v => v.Id == i);
vm.Selected = false;
vm.SelectedItemInfo = null;
}
BpStatus.StepSelectedIndex.Clear();
}
else
{
foreach (var i in _listBpSteps[BpStatus.CurrentStep])
{
var vm = HeroSelectorViewModels.First(v => v.Id == i);
vm.InteractionVisible = false;
}
BpStatus.CurrentStep--;
{
var i = _listBpSteps[BpStatus.CurrentStep].Last();
var vm = HeroSelectorViewModels.First(v => v.Id == i);
vm.Selected = false;
vm.SelectedItemInfo = null;
if (_listBpSteps[BpStatus.CurrentStep].Count > 1)
{
var vmSelected = HeroSelectorViewModels.First(v => v.Id != _listBpSteps[BpStatus.CurrentStep].First());
if (vmSelected != null)
BpStatus.StepSelectedIndex = new HashSet<int>() { vmSelected.Id };
else
BpStatus.StepSelectedIndex.Clear();
}
else
BpStatus.StepSelectedIndex.Clear();
}
}
InvokeScript("update", new List<Tuple<string, string>>
{
Tuple.Create("chose", string.Join("|",
HeroSelectorViewModels
.Where(vm => vm.SelectedItemInfo != null)
.Select(vm => vm.SelectedItemInfo.Id))),
Tuple.Create("map", BpStatus.Map),
Tuple.Create("lang", App.Language)
});
return;
}
var idList = new List<string>();
foreach (var vm in HeroSelectorViewModels)
{
if (vm.SelectedItemInfo != null)
idList.Add(vm.SelectedItemInfo.Id);
}
if (App.CustomConfigurationSettings.UploadBanSample && BanSteps.Contains(message.SelectorId) && !string.IsNullOrEmpty(message.ItemInfo?.Id) && message.ItemInfo.Id != "0")
{
if (_lastIds[message.SelectorId] != message.ItemInfo?.Id)
{
Task.Run(() => UploadSampleAsync(message.ItemInfo.Id, BanSteps.IndexOf(message.SelectorId)));
_lastIds[message.SelectorId] = message.ItemInfo?.Id;
}
}
InvokeScript("update", new List<Tuple<string, string>>
{
Tuple.Create("chose", string.Join("|", idList)),
Tuple.Create("map", BpStatus.Map),
Tuple.Create("lang", App.Language)
});
if (BpStatus.StepSelectedIndex.Contains(message.SelectorId) || // 修改本轮选过的英雄
!_listBpSteps[BpStatus.CurrentStep].Contains(message.SelectorId)) // 修改其他轮选过的英雄
{
// 修改英雄选择,无需处理
}
else
{
// 新英雄选择,判断本轮是否已选够英雄
BpStatus.StepSelectedIndex.Add(message.SelectorId);
if (BpStatus.StepSelectedIndex.Count == _listBpSteps[BpStatus.CurrentStep].Count)
{
// 选够了,下一步
if (BpStatus.CurrentStep < 11)
{
BpStatus.CurrentStep++;
ProcessStep();
}
}
}
}
catch (Exception)
{
// TODO Ignore for test, please remove the catch
}
}
19
Source : RegUsageCollector.cs
with MIT License
from bryanperris
with MIT License
from bryanperris
private void AddGprUsage(int index)
{
if (!m_UniqueGprSet.Contains(index))
{
m_UniqueGprSet.Add(index);
}
}
19
Source : RegUsageCollector.cs
with MIT License
from bryanperris
with MIT License
from bryanperris
private void AddCp0Usage(int index)
{
if (!m_UniqueCp0Set.Contains(index))
{
m_UniqueCp0Set.Add(index);
}
}
19
Source : RegUsageCollector.cs
with MIT License
from bryanperris
with MIT License
from bryanperris
private void AddFprUsage(DecodedInstruction inst, int index)
{
if (inst.Format == FpuValueType.FSingle)
{
if (!m_UniqueFprFSet.Contains(index))
{
m_UniqueFprFSet.Add(index);
}
}
else if (inst.Format == FpuValueType.FDouble)
{
if (!m_UniqueFprDSet.Contains(index))
{
m_UniqueFprDSet.Add(index);
}
}
else
{
Log.Warn("Cannot track FPR Word or Dword usage");
}
}
19
Source : MipsDebugger.cs
with MIT License
from bryanperris
with MIT License
from bryanperris
public void AppendGprRegisterWriteBreakpoint(int gpr)
{
if (!m_GPRWriteBreakpoints.Contains(gpr))
{
m_GPRWriteBreakpoints.Add(gpr);
}
}
19
Source : ClanMusicInfo.cs
with MIT License
from BtbN
with MIT License
from BtbN
public List<int> GetRandomSongs(int num)
{
HashSet<int> candidateIndexes = new HashSet<int>();
while (candidateIndexes.Count < num)
candidateIndexes.Add(rng.Next(musicIdList.Count));
List<int> result = candidateIndexes.Select(i => musicIdList[i]).ToList();
for (int i = result.Count - 1; i > 0; --i)
{
int k = rng.Next(i + 1);
int v = result[i];
result[i] = result[k];
result[k] = v;
}
return result;
}
19
Source : Octree.cs
with GNU General Public License v3.0
from BudgetToaster
with GNU General Public License v3.0
from BudgetToaster
private void FreeBranch(int ptr)
{
_freeStructureMemory.Add(ptr);
for (var i = 0; i < 8; i++)
{
var optr = ptr + i;
var type = (_data[optr] >> 31) & 1;
if(type == 0)
FreeBranch(_data[optr]);
else if(_data[optr] != 1 << 31)
FreeAttributes(_data[optr] & 0x7FFFFFFF);
}
}
19
Source : Octree.cs
with GNU General Public License v3.0
from BudgetToaster
with GNU General Public License v3.0
from BudgetToaster
private void FreeAttributes(int ptr)
{
_freeAttributeMemory.Add(ptr);
}
19
Source : IntervalSet.cs
with MIT License
from Butjok
with MIT License
from Butjok
public virtual HashSet<int> ToSet()
{
HashSet<int> s = new HashSet<int>();
foreach (Interval I in intervals)
{
int a = I.a;
int b = I.b;
for (int v = a; v <= b; v++)
{
s.Add(v);
}
}
return s;
}
19
Source : InputManager.cs
with MIT License
from CandyCoded
with MIT License
from CandyCoded
public static bool GetTouchDown(this GameObject gameObject, Camera mainCamera, ref int? currentFingerId,
out RaycastHit hit)
{
hit = new RaycastHit();
if (!touchSupported || touchCount <= 0)
{
return false;
}
foreach (var touch in touches)
{
if (currentFingerId.HasValue ||
activeFingerIds.Contains(touch.GetTouchId()) ||
!touch.phase.Equals(TouchPhase.Began) && !touch.phase.Equals(TouchPhase.Moved) ||
!RaycastToGameObject(gameObject, mainCamera, touch.GetTouchPosition(), out hit))
{
continue;
}
currentFingerId = touch.GetTouchId();
activeFingerIds.Add(currentFingerId.Value);
return true;
}
return false;
}
19
Source : InputManager.cs
with MIT License
from CandyCoded
with MIT License
from CandyCoded
public static bool GetTouchDown(this GameObject gameObject, Camera mainCamera, ref int? currentFingerId,
out RaycastHit2D hit)
{
hit = new RaycastHit2D();
if (!touchSupported || touchCount <= 0)
{
return false;
}
foreach (var touch in touches)
{
if (currentFingerId.HasValue ||
activeFingerIds.Contains(touch.GetTouchId()) ||
!touch.phase.Equals(TouchPhase.Began) && !touch.phase.Equals(TouchPhase.Moved) ||
!RaycastToGameObject(gameObject, mainCamera, touch.GetTouchPosition(), out hit))
{
continue;
}
currentFingerId = touch.GetTouchId();
activeFingerIds.Add(currentFingerId.Value);
return true;
}
return false;
}
19
Source : InputManager.cs
with MIT License
from CandyCoded
with MIT License
from CandyCoded
public static bool GetTouchDown(this GameObject gameObject, ref int? currentFingerId,
ref List<RaycastResult> hits)
{
if (hits == null)
{
hits = new List<RaycastResult>();
}
if (!touchSupported || touchCount <= 0)
{
return false;
}
foreach (var touch in touches)
{
if (currentFingerId.HasValue ||
activeFingerIds.Contains(touch.GetTouchId()) ||
!touch.phase.Equals(TouchPhase.Began) && !touch.phase.Equals(TouchPhase.Moved) ||
!RaycastToGameObject(gameObject, touch.GetTouchPosition(), ref hits))
{
continue;
}
currentFingerId = touch.GetTouchId();
activeFingerIds.Add(currentFingerId.Value);
return true;
}
return false;
}
19
Source : InputManager.cs
with MIT License
from CandyCoded
with MIT License
from CandyCoded
public static bool GetTouchDown(ref int? currentFingerId)
{
var touch = GetActiveTouch(TouchPhase.Began);
if (!touch.HasValue)
{
return false;
}
currentFingerId = touch.Value.GetTouchId();
activeFingerIds.Add(currentFingerId.Value);
return true;
}
19
Source : UpdateOrderLiveTestAlgorithm.cs
with Apache License 2.0
from Capnode
with Apache License 2.0
from Capnode
public override void OnData(Slice data)
{
if (!_security.HasData)
{
Log("::::: NO DATA :::::");
return;
}
// each month make an action
if (Time.Minute != _lastMinute && Time.Second == 0)
{
Log("");
Log("--------------Minute: " + Time.Minute);
Log("");
_lastMinute = Time.Minute;
// we'll submit the next type of order from the queue
var orderType = _orderTypesQueue.Dequeue();
Log("ORDER TYPE:: " + orderType);
var isLong = _quanreplacedy > 0;
var stopPrice = isLong ? (1 + StopPercentage) * _security.High : (1 - StopPercentage) * _security.Low;
var limitPrice = isLong ? (1 - LimitPercentage) * stopPrice : (1 + LimitPercentage) * stopPrice;
if (orderType == OrderType.Limit)
{
limitPrice = !isLong ? (1 + LimitPercentage) * _security.High : (1 - LimitPercentage) * _security.Low;
}
var request = new SubmitOrderRequest(orderType, SecType, Securities[_symbol].Symbol, _quanreplacedy, stopPrice, limitPrice, Time, orderType.ToString());
var ticket = Transactions.AddOrder(request);
_tickets.Add(ticket);
if ((decimal)Random.NextDouble() < ImmediateCancelPercentage)
{
Log("Immediate cancellation requested!");
_immediateCancellations.Add(ticket.OrderId);
}
}
else if (_tickets.Count > 0)
{
var ticket = _tickets.Last();
if (Time.Second > 15 && Time.Second < 30)
{
if (ticket.UpdateRequests.Count == 0 && ticket.Status.IsOpen())
{
Log(ticket.ToString());
ticket.Update(new UpdateOrderFields
{
Quanreplacedy = ticket.Quanreplacedy + Math.Sign(_quanreplacedy) * DeltaQuanreplacedy,
Tag = "Change quanreplacedy: " + Time
});
Log("UPDATE1:: " + ticket.UpdateRequests.Last());
}
}
else if (Time.Second > 29 && Time.Second < 45)
{
if (ticket.UpdateRequests.Count == 1 && ticket.Status.IsOpen())
{
Log(ticket.ToString());
ticket.Update(new UpdateOrderFields
{
LimitPrice = _security.Price * (1 - Math.Sign(ticket.Quanreplacedy) * LimitPercentageDelta),
StopPrice = _security.Price * (1 + Math.Sign(ticket.Quanreplacedy) * StopPercentageDelta),
Tag = "Change prices: " + Time
});
Log("UPDATE2:: " + ticket.UpdateRequests.Last());
}
}
else
{
if (ticket.UpdateRequests.Count == 2 && ticket.Status.IsOpen())
{
Log(ticket.ToString());
ticket.Cancel(Time + " and is still open!");
Log("CANCELLED:: " + ticket.CancelRequest);
}
}
}
}
19
Source : Driver.cs
with Apache License 2.0
from cdy816
with Apache License 2.0
from cdy816
public void OnRealTagChanged(TagChangedArg arg)
{
foreach (var vv in arg.AddedTags.Where(e => e.Value.StartsWith(this.Name) && !AllowTagIds.Contains(e.Key)))
{
AllowTagIds.Add(vv.Key);
}
foreach(var vv in arg.ChangedTags)
{
if(vv.Value.StartsWith(this.Name))
{
if(!AllowTagIds.Contains(vv.Key))
{
AllowTagIds.Add(vv.Key);
}
}
else
{
if(AllowTagIds.Contains(vv.Key))
{
AllowTagIds.Remove(vv.Key);
}
}
}
}
19
Source : RealDataServerProcess.cs
with Apache License 2.0
from cdy816
with Apache License 2.0
from cdy816
private void ProcessValueChangeNotify(string clientId, ByteBuffer block)
{
try
{
int minid = block.ReadInt();
int maxid = block.ReadInt();
HashSet<int> ids = new HashSet<int>();
for (int i = minid; i <= maxid; i++)
{
ids.Add(i);
lock (mMonitors)
{
if (!mMonitors.ContainsKey(i))
{
var vtag = mTagManager.GetTagById(i);
if(vtag!=null)
mtmp.Add(i, new MonitorTag() { Value = 0, RefCount = 1, Type = vtag.Type });
}
else
{
mMonitors[i].IncRef();
}
}
}
if (mCallBackRegistorIds.ContainsKey(clientId))
{
mCallBackRegistorIds[clientId] = ids;
}
else
{
mCallBackRegistorIds.Add(clientId, ids);
}
lock(mDataCounts)
if (!mDataCounts.ContainsKey(clientId))
{
mDataCounts.Add(clientId, 0);
}
Parent.AsyncCallback(clientId, ToByteBuffer(ApiFunConst.RealDataRequestFun, 1));
}
catch(Exception ex)
{
Parent.AsyncCallback(clientId, ToByteBuffer(ApiFunConst.RealDataRequestFun, 0));
Debug.Print(ex.Message);
}
}
19
Source : RealDataServerProcess.cs
with Apache License 2.0
from cdy816
with Apache License 2.0
from cdy816
private void ProcessValueChangeNotify(string clientId, ByteBuffer block)
{
try
{
int minid = block.ReadInt();
int maxid = block.ReadInt();
bool isall = false;
HashSet<int> ids = new HashSet<int>();
if (minid < 0)
{
ids.Add(-1);
isall = true;
}
else
{
for (int i = minid; i <= maxid; i++)
{
ids.Add(i);
}
}
if (mCallBackRegistorIds.ContainsKey(clientId))
{
mCallBackRegistorIds[clientId] = new Tuple<HashSet<int>, bool>( ids,isall);
}
else
{
mCallBackRegistorIds.Add(clientId, new Tuple<HashSet<int>, bool>(ids, isall));
}
if (!mDataCounts.ContainsKey(clientId))
{
mDataCounts.Add(clientId, 0);
}
}
catch(Exception ex)
{
Debug.Print(ex.Message);
}
}
19
Source : Driver.cs
with Apache License 2.0
from cdy816
with Apache License 2.0
from cdy816
public bool Start(IRealTagProduct tagQuery, ITagHisValueProduct tagHisValueService)
{
Load();
mService = new List<DataService>();
var vdds = tagQuery.GetTagByLinkAddress(this.Name + ":");
foreach (var vv in vdds)
{
if (!AllowTagNames.ContainsKey(vv.FullName))
AllowTagNames.Add(vv.FullName, vv.Id);
AllowTagIds.Add(vv.Id);
}
// AllowTagIds = new HashSet<int>(tagQuery.GetTagIdsByLinkAddress(this.Name+":"));
for (int i = mPort; i <= mEndPort; i++)
{
try
{
var mSvc = new DataService();
mSvc.Start(i);
mService.Add(mSvc);
}
catch
{
}
}
return true;
}
19
Source : EffectProcessorsContainer.cs
with MIT License
from centaurus-project
with MIT License
from centaurus-project
public void Add(IEffectProcessor<Effect> effectProcessor)
{
Effects.Add(effectProcessor.Effect);
effectProcessor.CommitEffect();
this.Aggregate(Envelope, effectProcessor.Effect);
if (effectProcessor.Effect.Account != 0)
AffectedAccounts.Add(effectProcessor.Effect.Account);
}
19
Source : BlockchainController.cs
with GNU General Public License v3.0
from chaincase-app
with GNU General Public License v3.0
from chaincase-app
[HttpGet("fees/{confirmationTargets}")]
[ProducesResponseType(200)] // Note: If you add typeof(SortedDictionary<int, FeeEstimationPair>) then swagger UI will visualize incorrectly.
[ProducesResponseType(400)]
[ResponseCache(Duration = 300, Location = ResponseCacheLocation.Client)]
public async Task<IActionResult> GetFeesAsync(string confirmationTargets)
{
if (string.IsNullOrWhiteSpace(confirmationTargets) || !ModelState.IsValid)
{
return BadRequest($"Invalid {nameof(confirmationTargets)} are provided.");
}
var confirmationTargetsInts = new HashSet<int>();
foreach (var targetParam in confirmationTargets.Split(',', StringSplitOptions.RemoveEmptyEntries))
{
if (int.TryParse(targetParam, out var target))
{
if (target < 2 || target > Constants.SevenDaysConfirmationTarget)
{
return BadRequest($"All requested confirmation target must be >= 2 AND <= {Constants.SevenDaysConfirmationTarget}.");
}
if (confirmationTargetsInts.Contains(target))
{
continue;
}
confirmationTargetsInts.Add(target);
}
else
{
return BadRequest($"Invalid {nameof(confirmationTargets)} are provided.");
}
}
var feeEstimations = new SortedDictionary<int, FeeEstimationPair>();
foreach (int target in confirmationTargetsInts)
{
// 1. Use the sanity check that under 2 satoshi per byte should not be displayed. To correct possible rounding errors.
// 2. Use the RPCResponse.Blocks output to avoid redundant RPC queries.
// 3. Use caching.
var conservativeResponse = await GetEstimateSmartFeeAsync(target, EstimateSmartFeeMode.Conservative);
var economicalResponse = await GetEstimateSmartFeeAsync(target, EstimateSmartFeeMode.Economical);
var conservativeFee = conservativeResponse.FeeRate.FeePerK.Satoshi / 1000;
var economicalFee = economicalResponse.FeeRate.FeePerK.Satoshi / 1000;
conservativeFee = Math.Max(conservativeFee, 2);
economicalFee = Math.Max(economicalFee, 2);
feeEstimations.Add(target, new FeeEstimationPair() { Conservative = conservativeFee, Economical = economicalFee });
}
return Ok(feeEstimations);
}
19
Source : PolygonValidator.cs
with MIT License
from Chaosed0
with MIT License
from Chaosed0
private static int CheckDuplicateIDs(IPolygon poly)
{
var ids = new HashSet<int>();
// Check for duplicate ids.
foreach (var p in poly.Points)
{
if (!ids.Add(p.id))
{
Log.Instance.Warning("Found duplicate vertex ids.", "PolygonValidator.IsConsistent()");
return 1;
}
}
return 0;
}
19
Source : MatrixOp.cs
with MIT License
from chen0040
with MIT License
from chen0040
public static double[][] GetUpperTriangularMatrix(double[][] A, out int rowExchangeOpCount)
{
double[][] B = Clone(A);
int colCount = B[0].Length;
int rowCount = B.Length;
HashSet<int> rows_left = new HashSet<int>();
for (int r = 0; r < rowCount; ++r)
{
rows_left.Add(r);
}
List<int> row_mapping = new List<int>();
for (int r = 0; r < rowCount; ++r)
{
row_mapping.Add(r);
}
rowExchangeOpCount = 0;
List<int> new_rows = new List<int>();
for (int c = 0; c < colCount; ++c)
{
List<int> nonzero_rows = GetRowsWithNonZeroAtColIndex(rows_left, B, c);
if (nonzero_rows.Count > 0)
{
int pivot_row = GetPivotRow(nonzero_rows, B, c);
new_rows.Add(pivot_row);
rows_left.Remove(pivot_row);
for (int i = 0; i < nonzero_rows.Count; ++i)
{
int r = nonzero_rows[i];
if (r != pivot_row)
{
double multiplier = B[r][c] / B[pivot_row][c];
for (int j = c; j < rowCount; ++j)
{
B[r][j] -= B[pivot_row][j] * multiplier;
}
}
}
}
}
foreach (int r in rows_left)
{
new_rows.Add(r);
}
for (int i = 0; i < new_rows.Count; ++i)
{
int new_row = new_rows[i];
int old_row = i;
if (new_row != old_row)
{
double[] temp = B[new_row];
B[new_row] = B[old_row];
B[old_row] = temp;
int new_row_index = i;
int old_row_index = new_rows.IndexOf(old_row);
Swap(new_rows, new_row_index, old_row_index);
rowExchangeOpCount++;
}
}
return B;
}
19
Source : ErrorHandler.cs
with MIT License
from chequer-io
with MIT License
from chequer-io
private ISet<int> Process(ParsingState start, int precedence)
{
if (_memo.TryGetValue(start, out ISet<int> result))
return result;
var endTokens = new HashSet<int>();
// Simulates the ATN by consuming input tokens and walking transitions.
// The ATN can be in multiple states (similar to an NFA)
var activeStates = new Queue<ParsingState>();
activeStates.Enqueue(start);
while (activeStates.TryDequeue(out var current))
{
var state = current._state;
int tokenIndex = current._tokenIndex;
bool suppressed = current._suppressed;
while (_stream.Get(tokenIndex).Channel == Lexer.Hidden)
{
// Ignore whitespace
tokenIndex++;
}
int currentToken = _stream.Get(tokenIndex).Type;
if (state.StateType == StateType.RuleStart)
{
int rule = state.ruleIndex;
if (_specialRules.TryGetValue(rule, out var specialRule))
{
if (!suppressed)
Record(tokenIndex, specialRule);
suppressed = true;
}
else if (_ignoredRules.Contains(rule))
{
// TODO expand ignored rules like we expand special rules
continue;
}
}
if (state is RuleStopState)
{
endTokens.Add(tokenIndex);
continue;
}
for (int i = 0; i < state.NumberOfTransitions; i++)
{
var transition = state.Transition(i);
switch (transition)
{
case RuleTransition ruleTransition:
{
var parsingState = new ParsingState(ruleTransition.target, tokenIndex, suppressed, _parser);
foreach (int endToken in Process(parsingState, ruleTransition.precedence))
activeStates.Enqueue(new ParsingState(ruleTransition.followState, endToken, suppressed, _parser));
break;
}
case PrecedencePredicateTransition predicateTransition:
{
if (precedence < predicateTransition.precedence)
{
activeStates.Enqueue(new ParsingState(predicateTransition.target, tokenIndex, suppressed, _parser));
}
break;
}
default:
{
if (transition.IsEpsilon)
{
activeStates.Enqueue(new ParsingState(transition.target, tokenIndex, suppressed, _parser));
}
else if (transition is WildcardTransition)
{
throw new NotSupportedException("not yet implemented: wildcard transition");
}
else
{
var labels = transition.Label;
if (transition is NotSetTransition)
{
labels = labels.Complement(IntervalSet.Of(TokenConstants.MinUserTokenType, _atn.maxTokenType));
}
// Surprisingly, TokenStream (i.e. BufferedTokenStream) may not have loaded all the tokens from the
// underlying stream. TokenStream.get() does not force tokens to be buffered -- it just returns what's
// in the current buffer, or fail with an IndexOutOfBoundsError. Since Antlr decided the error occurred
// within the current set of buffered tokens, stop when we reach the end of the buffer.
if (labels.Contains(currentToken) && tokenIndex < _stream.Size - 1)
{
activeStates.Enqueue(new ParsingState(transition.target, tokenIndex + 1, false, _parser));
}
else
{
if (!suppressed)
{
Record(tokenIndex, GetTokenNames(labels));
}
}
}
break;
}
}
}
}
result = endTokens;
_memo[start] = result;
return result;
}
19
Source : QueryPlanBuilder.QueryStrategy.cs
with MIT License
from ChilliCream
with MIT License
from ChilliCream
public static IEnumerable<QueryPlanNode> BuildDeferred(QueryPlanContext context)
{
var processed = new HashSet<int>();
while (context.Deferred.TryPop(out IFragment? fragment) &&
processed.Add(fragment.Id))
{
yield return Build(context, fragment.SelectionSet);
}
}
19
Source : LayerMaskTests.cs
with MIT License
from Chris3606
with MIT License
from Chris3606
public static TimeSpan TimeForGetRandomLayers(int iterations, int numLayers)
{
var layersToCheck = new HashSet<int>();
while (layersToCheck.Count != numLayers)
layersToCheck.Add(POSSIBLE_LAYERS.RandomItem());
return TimeForGetLayers(iterations, layersToCheck);
}
19
Source : ToStringTests.cs
with MIT License
from Chris3606
with MIT License
from Chris3606
[TestMethod]
public void ManualPrintSet()
{
var mySet = new HashSet<int>();
mySet.Add(1);
mySet.Add(1);
mySet.Add(3);
mySet.Add(2);
Console.WriteLine(mySet.ExtendToString());
Console.WriteLine("\nWith bar separators:");
Console.WriteLine(mySet.ExtendToString(separator: " | "));
}
19
Source : GCSegmentControl.cs
with MIT License
from chrisnas
with MIT License
from chrisnas
private void RenderFreeBlocks(DrawingContext dc, double sizePerPixel)
{
if (FreeBlocks == null)
return;
var height = ActualHeight * 0.6;
var y = ActualHeight * 0.2;
var freeBlocks = new HashSet<int>();
foreach (var freeBlock in FreeBlocks)
{
var relativeAddress = freeBlock.Address - SegmentStart;
var posInPixel = relativeAddress / sizePerPixel;
var widthInPixel = freeBlock.Size / sizePerPixel;
widthInPixel = (widthInPixel == 0) ? 1 : widthInPixel;
if (freeBlocks.Add((int)posInPixel))
{
dc.DrawRectangle(
_freeFillBrush, _freeOutlinePen,
new Rect(new Point(posInPixel, y), new Size(widthInPixel, height))
);
}
}
}
19
Source : TMP_FontAssetUtilities.cs
with MIT License
from chstetco
with MIT License
from chstetco
private static TMP_Character GetCharacterFromFontreplacedet_Internal(uint unicode, TMP_Fontreplacedet sourceFontreplacedet, bool includeFallbacks, FontStyles fontStyle, FontWeight fontWeight, out bool isAlternativeTypeface)
{
isAlternativeTypeface = false;
TMP_Character character = null;
#region FONT WEIGHT AND FONT STYLE HANDLING
// Determine if a font weight or style is used. If so check if an alternative typeface is replacedigned for the given weight and / or style.
bool isItalic = (fontStyle & FontStyles.Italic) == FontStyles.Italic;
if (isItalic || fontWeight != FontWeight.Regular)
{
// Get reference to the font weight pairs of the given font replacedet.
TMP_FontWeightPair[] fontWeights = sourceFontreplacedet.fontWeightTable;
int fontWeightIndex = 4;
switch (fontWeight)
{
case FontWeight.Thin:
fontWeightIndex = 1;
break;
case FontWeight.ExtraLight:
fontWeightIndex = 2;
break;
case FontWeight.Light:
fontWeightIndex = 3;
break;
case FontWeight.Regular:
fontWeightIndex = 4;
break;
case FontWeight.Medium:
fontWeightIndex = 5;
break;
case FontWeight.SemiBold:
fontWeightIndex = 6;
break;
case FontWeight.Bold:
fontWeightIndex = 7;
break;
case FontWeight.Heavy:
fontWeightIndex = 8;
break;
case FontWeight.Black:
fontWeightIndex = 9;
break;
}
TMP_Fontreplacedet temp = isItalic ? fontWeights[fontWeightIndex].italicTypeface : fontWeights[fontWeightIndex].regularTypeface;
if (temp != null)
{
if (temp.characterLookupTable.TryGetValue(unicode, out character))
{
isAlternativeTypeface = true;
return character;
}
if (temp.atlasPopulationMode == AtlasPopulationMode.Dynamic)
{
if (temp.TryAddCharacterInternal(unicode, out character))
{
isAlternativeTypeface = true;
return character;
}
// Check if the source font file contains the requested character.
//if (TryGetCharacterFromFontFile(unicode, fontreplacedet, out characterData))
//{
// isAlternativeTypeface = true;
// return characterData;
//}
// If we find the requested character, we add it to the font replacedet character table
// and return its character data.
// We also add this character to the list of characters we will need to add to the font atlas.
// We replacedume the font atlas has room otherwise this font replacedet should not be marked as dynamic.
// Alternatively, we could also add multiple pages of font atlas textures (feature consideration).
}
// At this point, we were not able to find the requested character in the alternative typeface
// so we check the source font replacedet and its potential fallbacks.
}
}
#endregion
// Search the source font replacedet for the requested character.
if (sourceFontreplacedet.characterLookupTable.TryGetValue(unicode, out character))
return character;
if (sourceFontreplacedet.atlasPopulationMode == AtlasPopulationMode.Dynamic)
{
if (sourceFontreplacedet.TryAddCharacterInternal(unicode, out character))
return character;
}
// Search fallback font replacedets if we still don't have a valid character and include fallback is set to true.
if (character == null && includeFallbacks && sourceFontreplacedet.fallbackFontreplacedetTable != null)
{
// Get reference to the list of fallback font replacedets.
List<TMP_Fontreplacedet> fallbackFontreplacedets = sourceFontreplacedet.fallbackFontreplacedetTable;
int fallbackCount = fallbackFontreplacedets.Count;
if (fallbackFontreplacedets != null && fallbackCount > 0)
{
for (int i = 0; i < fallbackCount; i++)
{
TMP_Fontreplacedet temp = fallbackFontreplacedets[i];
if (temp == null)
continue;
int id = temp.instanceID;
// Try adding font replacedet to search list. If already present skip to the next one otherwise check if it contains the requested character.
if (k_Searchedreplacedets.Add(id) == false)
continue;
// Add reference to this search query
sourceFontreplacedet.FallbackSearchQueryLookup.Add(id);
character = GetCharacterFromFontreplacedet_Internal(unicode, temp, true, fontStyle, fontWeight, out isAlternativeTypeface);
if (character != null)
return character;
}
}
}
return null;
}
19
Source : TMP_SpriteAsset.cs
with MIT License
from chstetco
with MIT License
from chstetco
public static TMP_Spritereplacedet SearchForSpriteByHashCode(TMP_Spritereplacedet spritereplacedet, int hashCode, bool includeFallbacks, out int spriteIndex)
{
// Make sure sprite replacedet is not null
if (spritereplacedet == null) { spriteIndex = -1; return null; }
spriteIndex = spritereplacedet.GetSpriteIndexFromHashcode(hashCode);
if (spriteIndex != -1)
return spritereplacedet;
// Initialize or clear list to Sprite replacedets that have already been searched.
if (k_searchedSpritereplacedets == null)
k_searchedSpritereplacedets = new HashSet<int>();
else
k_searchedSpritereplacedets.Clear();
int id = spritereplacedet.instanceID;
// Add to list of font replacedets already searched.
k_searchedSpritereplacedets.Add(id);
TMP_Spritereplacedet tempSpritereplacedet;
// Search potential fallbacks replacedigned to local sprite replacedet.
if (includeFallbacks && spritereplacedet.fallbackSpritereplacedets != null && spritereplacedet.fallbackSpritereplacedets.Count > 0)
{
tempSpritereplacedet = SearchForSpriteByHashCodeInternal(spritereplacedet.fallbackSpritereplacedets, hashCode, true, out spriteIndex);
if (spriteIndex != -1)
return tempSpritereplacedet;
}
// Search default sprite replacedet potentially replacedigned in the TMP Settings.
if (includeFallbacks && TMP_Settings.defaultSpritereplacedet != null)
{
tempSpritereplacedet = SearchForSpriteByHashCodeInternal(TMP_Settings.defaultSpritereplacedet, hashCode, true, out spriteIndex);
if (spriteIndex != -1)
return tempSpritereplacedet;
}
// Clear search list since we are now looking for the missing sprite character.
k_searchedSpritereplacedets.Clear();
uint missingSpriteCharacterUnicode = TMP_Settings.missingCharacterSpriteUnicode;
// Get sprite index for the given unicode
spriteIndex = spritereplacedet.GetSpriteIndexFromUnicode(missingSpriteCharacterUnicode);
if (spriteIndex != -1)
return spritereplacedet;
// Add current sprite replacedet to list of replacedets already searched.
k_searchedSpritereplacedets.Add(id);
// Search for the missing sprite character in the local sprite replacedet and potential fallbacks.
if (includeFallbacks && spritereplacedet.fallbackSpritereplacedets != null && spritereplacedet.fallbackSpritereplacedets.Count > 0)
{
tempSpritereplacedet = SearchForSpriteByUnicodeInternal(spritereplacedet.fallbackSpritereplacedets, missingSpriteCharacterUnicode, true, out spriteIndex);
if (spriteIndex != -1)
return tempSpritereplacedet;
}
// Search for the missing sprite character in the default sprite replacedet and potential fallbacks.
if (includeFallbacks && TMP_Settings.defaultSpritereplacedet != null)
{
tempSpritereplacedet = SearchForSpriteByUnicodeInternal(TMP_Settings.defaultSpritereplacedet, missingSpriteCharacterUnicode, true, out spriteIndex);
if (spriteIndex != -1)
return tempSpritereplacedet;
}
spriteIndex = -1;
return null;
}
19
Source : TMP_SpriteAsset.cs
with MIT License
from chstetco
with MIT License
from chstetco
private static TMP_Spritereplacedet SearchForSpriteByHashCodeInternal(List<TMP_Spritereplacedet> spritereplacedets, int hashCode, bool searchFallbacks, out int spriteIndex)
{
// Search through the list of sprite replacedets
for (int i = 0; i < spritereplacedets.Count; i++)
{
TMP_Spritereplacedet temp = spritereplacedets[i];
if (temp == null) continue;
int id = temp.instanceID;
// Skip sprite replacedet if it has already been searched.
if (k_searchedSpritereplacedets.Add(id) == false)
continue;
temp = SearchForSpriteByHashCodeInternal(temp, hashCode, searchFallbacks, out spriteIndex);
if (temp != null)
return temp;
}
spriteIndex = -1;
return null;
}
19
Source : TMP_UpdateManager.cs
with MIT License
from chstetco
with MIT License
from chstetco
private void InternalRegisterTextObjectForUpdate(TMP_Text textObject)
{
int id = textObject.GetInstanceID();
if (m_InternalUpdateLookup.Contains(id))
return;
m_InternalUpdateLookup.Add(id);
m_InternalUpdateQueue.Add(textObject);
}
19
Source : TMP_FontAssetUtilities.cs
with MIT License
from chstetco
with MIT License
from chstetco
static TMP_SpriteCharacter GetSpriteCharacterFromSpritereplacedet_Internal(uint unicode, TMP_Spritereplacedet spritereplacedet, bool includeFallbacks)
{
TMP_SpriteCharacter spriteCharacter;
// Search sprite replacedet for potential sprite character for the given unicode value
if (spritereplacedet.spriteCharacterLookupTable.TryGetValue(unicode, out spriteCharacter))
return spriteCharacter;
if (includeFallbacks)
{
List<TMP_Spritereplacedet> fallbackSpritereplacedet = spritereplacedet.fallbackSpritereplacedets;
if (fallbackSpritereplacedet != null && fallbackSpritereplacedet.Count > 0)
{
int fallbackCount = fallbackSpritereplacedet.Count;
for (int i = 0; i < fallbackCount; i++)
{
TMP_Spritereplacedet temp = fallbackSpritereplacedet[i];
if (temp == null)
continue;
int id = temp.instanceID;
// Try adding replacedet to search list. If already present skip to the next one otherwise check if it contains the requested character.
if (k_Searchedreplacedets.Add(id) == false)
continue;
spriteCharacter = GetSpriteCharacterFromSpritereplacedet_Internal(unicode, temp, true);
if (spriteCharacter != null)
return spriteCharacter;
}
}
}
return null;
}
19
Source : TMP_SpriteAsset.cs
with MIT License
from chstetco
with MIT License
from chstetco
public static TMP_Spritereplacedet SearchForSpriteByUnicode(TMP_Spritereplacedet spritereplacedet, uint unicode, bool includeFallbacks, out int spriteIndex)
{
// Check to make sure sprite replacedet is not null
if (spritereplacedet == null) { spriteIndex = -1; return null; }
// Get sprite index for the given unicode
spriteIndex = spritereplacedet.GetSpriteIndexFromUnicode(unicode);
if (spriteIndex != -1)
return spritereplacedet;
// Initialize list to track instance of Sprite replacedets that have already been searched.
if (k_searchedSpritereplacedets == null)
k_searchedSpritereplacedets = new HashSet<int>();
else
k_searchedSpritereplacedets.Clear();
// Get instance ID of sprite replacedet and add to list.
int id = spritereplacedet.GetInstanceID();
k_searchedSpritereplacedets.Add(id);
// Search potential fallback sprite replacedets if includeFallbacks is true.
if (includeFallbacks && spritereplacedet.fallbackSpritereplacedets != null && spritereplacedet.fallbackSpritereplacedets.Count > 0)
return SearchForSpriteByUnicodeInternal(spritereplacedet.fallbackSpritereplacedets, unicode, true, out spriteIndex);
// Search default sprite replacedet potentially replacedigned in the TMP Settings.
if (includeFallbacks && TMP_Settings.defaultSpritereplacedet != null)
return SearchForSpriteByUnicodeInternal(TMP_Settings.defaultSpritereplacedet, unicode, true, out spriteIndex);
spriteIndex = -1;
return null;
}
19
Source : TMP_FontAssetUtilities.cs
with MIT License
from chstetco
with MIT License
from chstetco
public static TMP_SpriteCharacter GetSpriteCharacterFromSpritereplacedet(uint unicode, TMP_Spritereplacedet spritereplacedet, bool includeFallbacks)
{
// Make sure we have a valid sprite replacedet to search
if (spritereplacedet == null)
return null;
TMP_SpriteCharacter spriteCharacter;
// Search sprite replacedet for potential sprite character for the given unicode value
if (spritereplacedet.spriteCharacterLookupTable.TryGetValue(unicode, out spriteCharacter))
return spriteCharacter;
if (includeFallbacks)
{
// Clear searched replacedets
if (k_Searchedreplacedets == null)
k_Searchedreplacedets = new HashSet<int>();
else
k_Searchedreplacedets.Clear();
// Add current sprite replacedet to already searched replacedets.
k_Searchedreplacedets.Add(spritereplacedet.instanceID);
List<TMP_Spritereplacedet> fallbackSpritereplacedet = spritereplacedet.fallbackSpritereplacedets;
if (fallbackSpritereplacedet != null && fallbackSpritereplacedet.Count > 0)
{
int fallbackCount = fallbackSpritereplacedet.Count;
for (int i = 0; i < fallbackCount; i++)
{
TMP_Spritereplacedet temp = fallbackSpritereplacedet[i];
if (temp == null)
continue;
int id = temp.instanceID;
// Try adding replacedet to search list. If already present skip to the next one otherwise check if it contains the requested character.
if (k_Searchedreplacedets.Add(id) == false)
continue;
spriteCharacter = GetSpriteCharacterFromSpritereplacedet_Internal(unicode, temp, true);
if (spriteCharacter != null)
return spriteCharacter;
}
}
}
return null;
}
19
Source : TMP_SpriteAsset.cs
with MIT License
from chstetco
with MIT License
from chstetco
private static TMP_Spritereplacedet SearchForSpriteByUnicodeInternal(List<TMP_Spritereplacedet> spritereplacedets, uint unicode, bool includeFallbacks, out int spriteIndex)
{
for (int i = 0; i < spritereplacedets.Count; i++)
{
TMP_Spritereplacedet temp = spritereplacedets[i];
if (temp == null) continue;
int id = temp.GetInstanceID();
// Skip sprite replacedet if it has already been searched.
if (k_searchedSpritereplacedets.Add(id) == false)
continue;
temp = SearchForSpriteByUnicodeInternal(temp, unicode, includeFallbacks, out spriteIndex);
if (temp != null)
return temp;
}
spriteIndex = -1;
return null;
}
19
Source : TMP_UpdateManager.cs
with MIT License
from chstetco
with MIT License
from chstetco
private void InternalRegisterTextElementForLayoutRebuild(TMP_Text element)
{
int id = element.GetInstanceID();
if (m_LayoutQueueLookup.Contains(id))
return;
m_LayoutQueueLookup.Add(id);
m_LayoutRebuildQueue.Add(element);
}
19
Source : TMP_UpdateManager.cs
with MIT License
from chstetco
with MIT License
from chstetco
private void InternalRegisterTextElementForGraphicRebuild(TMP_Text element)
{
int id = element.GetInstanceID();
if (m_GraphicQueueLookup.Contains(id))
return;
m_GraphicQueueLookup.Add(id);
m_GraphicRebuildQueue.Add(element);
}
19
Source : TMP_FontAssetUtilities.cs
with MIT License
from chstetco
with MIT License
from chstetco
public static TMP_SpriteCharacter GetSpriteCharacterFromSpritereplacedet(uint unicode, TMP_Spritereplacedet spritereplacedet, bool includeFallbacks)
{
// Make sure we have a valid sprite replacedet to search
if (spritereplacedet == null)
return null;
TMP_SpriteCharacter spriteCharacter;
// Search sprite replacedet for potential sprite character for the given unicode value
if (spritereplacedet.spriteCharacterLookupTable.TryGetValue(unicode, out spriteCharacter))
return spriteCharacter;
if (includeFallbacks)
{
// Clear searched replacedets
if (k_Searchedreplacedets == null)
k_Searchedreplacedets = new HashSet<int>();
else
k_Searchedreplacedets.Clear();
// Add current sprite replacedet to already searched replacedets.
k_Searchedreplacedets.Add(spritereplacedet.instanceID);
List<TMP_Spritereplacedet> fallbackSpritereplacedet = spritereplacedet.fallbackSpritereplacedets;
if (fallbackSpritereplacedet != null && fallbackSpritereplacedet.Count > 0)
{
int fallbackCount = fallbackSpritereplacedet.Count;
for (int i = 0; i < fallbackCount; i++)
{
TMP_Spritereplacedet temp = fallbackSpritereplacedet[i];
if (temp == null)
continue;
int id = temp.instanceID;
// Try adding replacedet to search list. If already present skip to the next one otherwise check if it contains the requested character.
if (k_Searchedreplacedets.Add(id) == false)
continue;
spriteCharacter = GetSpriteCharacterFromSpritereplacedet_Internal(unicode, temp, true);
if (spriteCharacter != null)
return spriteCharacter;
}
}
}
return null;
}
19
Source : TMP_UpdateManager.cs
with MIT License
from chstetco
with MIT License
from chstetco
private void InternalRegisterTextElementForCullingUpdate(TMP_Text element)
{
int id = element.GetInstanceID();
if (m_CullingUpdateLookup.Contains(id))
return;
m_CullingUpdateLookup.Add(id);
m_CullingUpdateQueue.Add(element);
}
19
Source : TMP_UpdateRegistery.cs
with MIT License
from chstetco
with MIT License
from chstetco
private bool InternalRegisterCanvasElementForLayoutRebuild(ICanvasElement element)
{
int id = (element as Object).GetInstanceID();
if (m_LayoutQueueLookup.Contains(id))
return false;
m_LayoutQueueLookup.Add(id);
m_LayoutRebuildQueue.Add(element);
return true;
}
19
Source : TMP_UpdateRegistery.cs
with MIT License
from chstetco
with MIT License
from chstetco
private bool InternalRegisterCanvasElementForGraphicRebuild(ICanvasElement element)
{
int id = (element as Object).GetInstanceID();
if (m_GraphicQueueLookup.Contains(id))
return false;
m_GraphicQueueLookup.Add(id);
m_GraphicRebuildQueue.Add(element);
return true;
}
19
Source : EventInformationTableFactory.cs
with Apache License 2.0
from Cinegy
with Apache License 2.0
from Cinegy
public void AddPacket(TsPacket packet)
{
CheckPid(packet.Pid);
if (packet.PayloadUnitStartIndicator)
{
InProgressTable = new EventInformationTable { Pid = packet.Pid, PointerField = packet.Payload[0] };
if (InProgressTable.PointerField > packet.Payload.Length)
{
Debug.replacedert(true, "Event Information Table has packet pointer outside the packet.");
}
var pos = 1 + InProgressTable.PointerField;
InProgressTable.VersionNumber = (byte)(packet.Payload[pos + 5] & 0x3E);
InProgressTable.TableId = packet.Payload[pos];
//TODO: Refactor with enum for well-known table IDs, and add option below as filter
if (InProgressTable.TableId != 0x4e)
{
InProgressTable = null;
return;
}
if (EventInformationTable?.VersionNumber != InProgressTable.VersionNumber)
{
//if the version number of any section jumps, we need to refresh
_sectionsCompleted = new HashSet<int>();
EventInformationItems = new List<EventInformationItem>();
}
InProgressTable.SectionLength =
(short)(((packet.Payload[pos + 1] & 0x3) << 8) + packet.Payload[pos + 2]);
InProgressTable.SericeId = (ushort)((packet.Payload[pos + 3] << 8) + packet.Payload[pos + 4]);
InProgressTable.CurrentNextIndicator = (packet.Payload[pos + 5] & 0x1) != 0;
InProgressTable.SectionNumber = packet.Payload[pos + 6];
InProgressTable.LastSectionNumber = packet.Payload[pos + 7];
InProgressTable.TransportStreamId = (ushort)((packet.Payload[pos + 8] << 8) + packet.Payload[pos + 9]);
InProgressTable.OriginalNetworkId = (ushort)((packet.Payload[pos + 10] << 8) + packet.Payload[pos + 11]);
}
if (InProgressTable == null) return;
if (_sectionsCompleted.Contains(InProgressTable.SectionNumber))
{
InProgressTable = null;
return;
}
AddData(packet);
if (!HasAllBytes()) return;
InProgressTable.SegmentLastSectionNumber = (Data[InProgressTable.PointerField + 13]);
InProgressTable.LastTableId = (Data[InProgressTable.PointerField + 14]);
var startOfNextField = (ushort)(InProgressTable.PointerField + 15);
var transportStreamLoopEnd = (ushort)(InProgressTable.SectionLength - 4);
var items = new List<EventInformationItem>();
while (startOfNextField < transportStreamLoopEnd)
{
var item = new EventInformationItem
{
EventId = (ushort)((Data[startOfNextField] << 8) + Data[startOfNextField + 1]),
StartTime = (ulong)(((ulong)(Data[startOfNextField + 2]) << 32) + ((ulong)(Data[startOfNextField + 3]) << 24) + ((ulong)(Data[startOfNextField + 4]) << 16) + ((ulong)(Data[startOfNextField + 5]) << 8) + ((ulong)(Data[startOfNextField + 6]))),
Duration = (uint)((Data[startOfNextField + 7] << 16) + (Data[startOfNextField + 8] << 8) + Data[startOfNextField + 9]),
RunningStatus = (byte)((Data[startOfNextField + 10] >> 5) & 0x07),
FreeCAMode = (bool)((Data[startOfNextField + 10] & 0x10) == 0x10),
DescriptorsLoopLength = (ushort)(((Data[startOfNextField + 10] & 0x3) << 8) + Data[startOfNextField + 11])
};
var descriptors = new List<Descriptor>();
startOfNextField = (ushort)(startOfNextField + 12);
var endOfDescriptors = (ushort)(startOfNextField + item.DescriptorsLoopLength);
if (endOfDescriptors > Data.Length)
{
throw new InvalidDataException("Descriptor data in Event Information is marked beyond available data");
}
while (startOfNextField < endOfDescriptors)
{
var des = DescriptorFactory.DescriptorFromData(Data, startOfNextField);
descriptors.Add(des);
startOfNextField += (ushort)(des.DescriptorLength + 2);
}
item.Descriptors = descriptors;
items.Add(item);
}
InProgressTable.Items = items;
EventInformationItems.AddRange(items);
if(InProgressTable.VersionNumber == EventInformationTable?.VersionNumber) return;
EventInformationTable = InProgressTable;
_sectionsCompleted.Add(InProgressTable.SectionNumber);
OnTableChangeDetected();
}
19
Source : NetworkInformationTableFactory.cs
with Apache License 2.0
from Cinegy
with Apache License 2.0
from Cinegy
public void AddPacket(TsPacket packet)
{
CheckPid(packet.Pid);
if (packet.PayloadUnitStartIndicator)
{
InProgressTable = new NetworkInformationTable { Pid = packet.Pid, PointerField = packet.Payload[0] };
if (InProgressTable.PointerField > packet.Payload.Length)
{
Debug.replacedert(true, "Network Information Table has packet pointer outside the packet.");
}
var pos = 1 + InProgressTable.PointerField;
InProgressTable.VersionNumber = (byte)(packet.Payload[pos + 5] & 0x3E);
InProgressTable.TableId = packet.Payload[pos];
//TODO: Refactor with enum for well-known table IDs, and add option below as filter
if (InProgressTable.TableId != 0x40)
{
InProgressTable = null;
return;
}
if (NetworkInformationTable?.VersionNumber != InProgressTable.VersionNumber)
{
//if the version number of any section jumps, we need to refresh
_sectionsCompleted = new HashSet<int>();
NetworkInformationItems = new List<NetworkInformationItem>();
}
InProgressTable.SectionLength =
(short)(((packet.Payload[pos + 1] & 0x3) << 8) + packet.Payload[pos + 2]);
InProgressTable.TransportStreamId = (ushort)((packet.Payload[pos + 3] << 8) + packet.Payload[pos + 4]);
InProgressTable.CurrentNextIndicator = (packet.Payload[pos + 5] & 0x1) != 0;
InProgressTable.SectionNumber = packet.Payload[pos + 6];
InProgressTable.LastSectionNumber = packet.Payload[pos + 7];
}
if (InProgressTable == null) return;
if (_sectionsCompleted.Contains(InProgressTable.SectionNumber))
{
InProgressTable = null;
return;
}
AddData(packet);
if (!HasAllBytes()) return;
InProgressTable.NetworkDescriptorsLength = (ushort)(((Data[InProgressTable.PointerField + 9] & 0x3) << 8) + Data[InProgressTable.PointerField + 10]);
var startOfNextField = (ushort)(InProgressTable.PointerField + 11);
List<Descriptor> descriptors = new List<Descriptor>();
var endOfDescriptors = InProgressTable.PointerField + 11 + InProgressTable.NetworkDescriptorsLength;
if (endOfDescriptors > Data.Length)
{
throw new InvalidDataException("Descriptor data in Network Information is marked beyond available data");
}
while (startOfNextField < endOfDescriptors)
{
Descriptor des = DescriptorFactory.DescriptorFromData(Data, startOfNextField);
descriptors.Add(des);
startOfNextField += (byte)(des.DescriptorLength + 2);
}
InProgressTable.Descriptors = descriptors;
InProgressTable.TransportStreamLoopLength = (ushort)(((Data[startOfNextField] & 0x3) << 8) + Data[startOfNextField + 1]);
startOfNextField += 2;
var transportStreamLoopEnd = (byte)(startOfNextField + InProgressTable.TransportStreamLoopLength);
var items = new List<NetworkInformationItem>();
while (startOfNextField < transportStreamLoopEnd)
{
var item = new NetworkInformationItem
{
TransportStreamId = (ushort)((Data[startOfNextField] << 8) + Data[startOfNextField + 1]),
OriginalNetworkId = (ushort)((Data[startOfNextField + 2] << 8) + Data[startOfNextField + 3]),
ReservedFutureUse = (byte)((Data[startOfNextField + 4] >> 4) & 0x0F),
TransportDescriptorsLength = (ushort)(((Data[startOfNextField + 4] & 0x3) << 8) + Data[startOfNextField + 5])
};
descriptors = new List<Descriptor>();
startOfNextField = (byte)(startOfNextField + 6);
endOfDescriptors = (byte)(startOfNextField + item.TransportDescriptorsLength);
if (endOfDescriptors > Data.Length)
{
throw new InvalidDataException("Descriptor data in Network Information Item is marked beyond available data");
}
while (startOfNextField < endOfDescriptors)
{
Descriptor des = DescriptorFactory.DescriptorFromData(Data, startOfNextField);
descriptors.Add(des);
startOfNextField += (byte)(des.DescriptorLength + 2);
}
item.Descriptors = descriptors;
items.Add(item);
}
InProgressTable.Items = items;
NetworkInformationItems.AddRange(items);
NetworkInformationTable = InProgressTable;
_sectionsCompleted.Add(InProgressTable.SectionNumber);
OnTableChangeDetected();
}
See More Examples