本文整理汇总了C#中BlockList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# BlockList.Add方法的具体用法?C# BlockList.Add怎么用?C# BlockList.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlockList
的用法示例。
在下文中一共展示了BlockList.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GameWorld
public GameWorld(int width, int height, ContentManager Content)
{
screenWidth = width;
screenHeight = height;
random = new Random();
gameState = GameState.Menu;
inputHelper = new InputHelper();
block = Content.Load<Texture2D>("block");
reset = Content.Load<Texture2D>("reset");
font = Content.Load<SpriteFont>("SpelFont");
font2 = Content.Load<SpriteFont>("SpriteFont1");
font3 = Content.Load<SpriteFont>("SpriteFont2");
playButton = Content.Load<Texture2D>("Play");
optionsButton = Content.Load<Texture2D>("Options");
backButton = Content.Load<Texture2D>("Back");
polytris = Content.Load<Texture2D>("Polytris");
grid = new TetrisGrid(block);
level = 1;
levelspeed = 1;
score = 0;
i = (int)random.Next(7) + 1;
i2 = (int)random.Next(7) + 1;
blockcounter = 1;
blocks = new BlockList(block, Content); //Voegen de verschillende blockobjecten toe aan de lijst
block1 = new Block1(block, Content);
blocks.Add(block1, 1);
block2 = new Block2(block, Content);
blocks.Add(block2, 2);
block3 = new Block3(block, Content);
blocks.Add(block3, 3);
block4 = new Block4(block, Content);
blocks.Add(block4, 4);
block5 = new Block5(block, Content);
blocks.Add(block5, 5);
block6 = new Block6(block, Content);
blocks.Add(block6, 6);
block7 = new Block7(block, Content);
blocks.Add(block7, 7);
//Voegen de verschillende blockobjecten toe aan een tweede lijst voor het tekenen van het volgende blokje
block1res = new Block1(block, Content);
blocks.AddToReserve(block1res, 1);
block2res = new Block2(block, Content);
blocks.AddToReserve(block2res, 2);
block3res = new Block3(block, Content);
blocks.AddToReserve(block3res, 3);
block4res = new Block4(block, Content);
blocks.AddToReserve(block4res, 4);
block5res = new Block5(block, Content);
blocks.AddToReserve(block5res, 5);
block6res = new Block6(block, Content);
blocks.AddToReserve(block6res, 6);
block7res = new Block7(block, Content);
blocks.AddToReserve(block7res, 7);
options = new Options(block, reset, backButton, width, height, font, blocks);
menu = new Menu(playButton, optionsButton, polytris, width, height);
gameOver = new GameOver(backButton, width, height);
}
示例2: Run
public double Run(double[] data, int detailLevel)
{
var sb = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sb.Append(data[i]);
if (i < data.Length - 1) sb.Append(",");
}
string datastring = sb.ToString();
var textBlock = new ImportFromTextBlock
{
Text = datastring,
ColumnSeparator = ",",
SignalStart = 0,
SignalNameInFirstColumn = false
};
var dwtBlock = new DWTBlock
{
WaveletName = "db10",
Level = detailLevel,
ExtensionMode = SignalExtension.ExtensionMode.ZeroPadding
};
var b = new BlockList();
b.Add(textBlock);
b.Add(dwtBlock);
textBlock.ConnectTo(dwtBlock);
b.ExecuteAll();
int length = dwtBlock.OutputNodes[dwtBlock.OutputNodes.Count-1].Object[detailLevel - 1].Samples.Length;
double val = dwtBlock.OutputNodes[dwtBlock.OutputNodes.Count-1].Object[detailLevel - 1].Samples[length - 1];
return val;
}
示例3: TestAddRejectsBadIndexes
public virtual void TestAddRejectsBadIndexes()
{
BlockList<int> list = new BlockList<int>(4);
list.AddItem(Sharpen.Extensions.ValueOf(41));
try
{
list.Add(-1, Sharpen.Extensions.ValueOf(42));
}
catch (IndexOutOfRangeException badIndex)
{
NUnit.Framework.Assert.AreEqual((-1).ToString(), badIndex.Message);
}
try
{
list.Add(4, Sharpen.Extensions.ValueOf(42));
}
catch (IndexOutOfRangeException badIndex)
{
NUnit.Framework.Assert.AreEqual(4.ToString(), badIndex.Message);
}
}
示例4: FFTTransform
public static List<double> FFTTransform(List<double> serie)
{
//Declaring the blocks
var inputSeriesBlock = new InputSeriesBlock();
inputSeriesBlock.SetSeries(serie);
var outputSeriesBlock = new OutputSeriesBlock();
var fFTBlock = new FFTBlock
{
Mode = ManagedFFTModeEnum.UseLookupTable
};
//Connecting the blocks
inputSeriesBlock.OutputNodes[0].ConnectTo(fFTBlock.InputNodes[0]);
fFTBlock.OutputNodes[1].ConnectTo(outputSeriesBlock.InputNodes[0]);
//Appending the blocks to a block list and execute all
var blockList = new BlockList();
blockList.Add(inputSeriesBlock);
blockList.Add(fFTBlock);
blockList.Add(outputSeriesBlock);
blockList.ExecuteAll();
return outputSeriesBlock.GetSeries();
}
示例5: CoerceFromTypeUnion
protected virtual Expression CoerceFromTypeUnion(Expression source, TypeUnion sourceType, TypeNode targetType, bool explicitCoercion, TypeNode originalTargetType, TypeViewer typeViewer){
if (source == null || sourceType == null || targetType == null) return null;
if (targetType == SystemTypes.Object) return this.CoerceTypeUnionToObject(source, typeViewer);
int cErrors = (this.Errors != null) ? this.Errors.Count : 0;
if (explicitCoercion){
Method coercion = this.UserDefinedExplicitCoercionMethod(source, sourceType, targetType, false, originalTargetType, typeViewer);
if (coercion != null && coercion.ReturnType == targetType && coercion.Parameters != null && coercion.Parameters[0] != null &&
this.ImplicitCoercionFromTo(sourceType, coercion.Parameters[0].Type, typeViewer))
return this.ImplicitCoercion(new MethodCall(new MemberBinding(null, coercion), new ExpressionList(source), NodeType.Call, coercion.ReturnType),
targetType, typeViewer);
}
Method getTag = TypeViewer.GetTypeView(typeViewer, sourceType).GetMethod(StandardIds.GetTag);
if (getTag == null) return null;
Method getValue = TypeViewer.GetTypeView(typeViewer, sourceType).GetMethod(StandardIds.GetValue);
if (getValue == null) return null;
Local src = new Local(sourceType);
Local srcOb = new Local(SystemTypes.Object, source.SourceContext);
Local tgt = new Local(targetType);
Expression callGetTag = new MethodCall(new MemberBinding(new UnaryExpression(src, NodeType.AddressOf), getTag), null);
Expression callGetValue = new MethodCall(new MemberBinding(new UnaryExpression(src, NodeType.AddressOf), getValue), null);
TypeNodeList types = sourceType.Types;
int n = types == null ? 0 : types.Count;
Block endOfSwitch = new Block();
StatementList statements = new StatementList(5+n);
statements.Add(new AssignmentStatement(src, source));
statements.Add(new AssignmentStatement(srcOb, callGetValue));
BlockList cases = new BlockList(n);
statements.Add(new SwitchInstruction(callGetTag, cases));
bool hadCoercion = false;
Block eb = new Block(new StatementList(1));
Construct c = new Construct(new MemberBinding(null, SystemTypes.InvalidCastException.GetConstructor()), null, SystemTypes.InvalidCastException);
eb.Statements.Add(new Throw(c));
for (int i = 0; i < n; i++){
TypeNode t = types[i];
if (t == null) continue;
if (!explicitCoercion && !this.ImplicitCoercionFromTo(t, targetType, typeViewer)) return null;
Expression expr = this.ExplicitCoercion(srcOb, t, typeViewer);
if (expr == null) return null;
expr = this.ExplicitCoercion(expr, targetType, typeViewer);
if (expr == null) {
cases.Add(eb);
statements.Add(eb);
}
else {
Block b = new Block(new StatementList(2));
hadCoercion = true;
expr.SourceContext = srcOb.SourceContext;
b.Statements.Add(new AssignmentStatement(tgt, expr));
b.Statements.Add(new Branch(null, endOfSwitch));
cases.Add(b);
statements.Add(b);
}
}
if (this.Errors != null) {
for (int ie = cErrors, ne = this.Errors.Count; ie < ne; ie++) {
this.Errors[ie] = null;
}
}
if (!hadCoercion) return null;
statements.Add(endOfSwitch);
statements.Add(new ExpressionStatement(tgt));
return new BlockExpression(new Block(statements));
//TODO: wrap this in a CoerceTypeUnion node so that source code can be reconstructed easily
}
示例6: TestAddSlowPath
public virtual void TestAddSlowPath()
{
BlockList<string> list = new BlockList<string>(4);
string fooStr = "foo";
string barStr = "bar";
string foobarStr = "foobar";
string firstStr = "first";
string zeroStr = "zero";
list.AddItem(fooStr);
list.AddItem(barStr);
list.AddItem(foobarStr);
NUnit.Framework.Assert.AreEqual(3, list.Count);
list.Add(1, firstStr);
NUnit.Framework.Assert.AreEqual(4, list.Count);
NUnit.Framework.Assert.AreSame(fooStr, list[0]);
NUnit.Framework.Assert.AreSame(firstStr, list[1]);
NUnit.Framework.Assert.AreSame(barStr, list[2]);
NUnit.Framework.Assert.AreSame(foobarStr, list[3]);
list.Add(0, zeroStr);
NUnit.Framework.Assert.AreEqual(5, list.Count);
NUnit.Framework.Assert.AreSame(zeroStr, list[0]);
NUnit.Framework.Assert.AreSame(fooStr, list[1]);
NUnit.Framework.Assert.AreSame(firstStr, list[2]);
NUnit.Framework.Assert.AreSame(barStr, list[3]);
NUnit.Framework.Assert.AreSame(foobarStr, list[4]);
}
示例7: TestAddToEnd
public virtual void TestAddToEnd()
{
BlockList<int> list = new BlockList<int>(4);
int cnt = BlockList<int>.BLOCK_SIZE * 3;
for (int i = 0; i < cnt; i++)
{
list.AddItem(Sharpen.Extensions.ValueOf(42 + i));
}
NUnit.Framework.Assert.AreEqual(cnt, list.Count);
for (int i_1 = 0; i_1 < cnt; i_1++)
{
NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.ValueOf(42 + i_1), list[i_1]);
}
list.Clear();
NUnit.Framework.Assert.AreEqual(0, list.Count);
NUnit.Framework.Assert.IsTrue(list.IsEmpty());
for (int i_2 = 0; i_2 < cnt; i_2++)
{
list.Add(i_2, Sharpen.Extensions.ValueOf(42 + i_2));
}
NUnit.Framework.Assert.AreEqual(cnt, list.Count);
for (int i_3 = 0; i_3 < cnt; i_3++)
{
NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.ValueOf(42 + i_3), list[i_3]);
}
}
示例8: VisitTypeswitchCaseList
public virtual void VisitTypeswitchCaseList(TypeswitchCaseList oldCases, BlockList targets, StatementList statements, Block nextStatement, Local temp){
for (int i = 0, n = oldCases.Count; i < n; i++){
TypeswitchCase tcase = oldCases[i];
StatementList stats = new StatementList(3);
Block b = new Block(stats);
if (tcase != null){
Expression expr = null;
if (tcase.LabelType.IsValueType)
expr = new AddressDereference(new BinaryExpression(temp, new Literal(tcase.LabelType, SystemTypes.Type), NodeType.Unbox), tcase.LabelType);
else
expr = new BinaryExpression(temp, new Literal(tcase.LabelType, SystemTypes.Type), NodeType.Castclass);
stats.Add(new AssignmentStatement(this.VisitTargetExpression(tcase.LabelVariable), expr));
stats.Add(this.VisitBlock(tcase.Body));
}
stats.Add(new Branch(null, nextStatement));
statements.Add(b);
targets.Add(b);
}
}
示例9: BuildAxisClosureUnion
public virtual void BuildAxisClosureUnion(Expression source, AxisBuildState state, SwitchAccessor swa, bool yieldResult, Block block, BlockScope scope) {
TypeUnion tu = source.Type as TypeUnion;
Debug.Assert(tu != null, "Switch accessor must have type union");
if (!this.IsLocal(source)) {
Expression loc = this.NewClosureLocal(source.Type, scope);
block.Statements.Add(new AssignmentStatement(loc, source));
source = loc;
}
// determine type union tag and value
Method mgetvalue = this.GetTypeView(tu).GetMethod(StandardIds.GetValue);
MethodCall mcgetvalue = new MethodCall(new MemberBinding(source, mgetvalue), null);
mcgetvalue.Type = mgetvalue.ReturnType;
Local locValue = new Local(SystemTypes.Object);
block.Statements.Add(new AssignmentStatement(locValue, mcgetvalue));
Method mgettag = this.GetTypeView(tu).GetMethod(StandardIds.GetTag);
MethodCall mcgettag = new MethodCall(new MemberBinding(source, mgettag), null);
mcgettag.Type = mgettag.ReturnType;
Local locTag = new Local(SystemTypes.UInt32);
block.Statements.Add(new AssignmentStatement(locTag, mcgettag));
// switch on type union tag
BlockList blocks = new BlockList(swa.Accessors.Count);
Block endBlock = new Block(null);
foreach( int id in swa.Accessors.Keys ) {
Accessor acc = (Accessor) swa.Accessors[id];
Block caseBlock = new Block(new StatementList(3));
blocks.Add(caseBlock);
block.Statements.Add(new Branch(new BinaryExpression(locTag, new Literal(id, SystemTypes.Int32), NodeType.Eq), caseBlock));
Expression locvar = this.NewClosureLocal(swa.Type.Types[id], scope);
caseBlock.Statements.Add(new AssignmentStatement(locvar, this.Unbox(locValue, locvar.Type)));
this.BuildAxisClosureExpression(locvar, state, acc, yieldResult, caseBlock, scope);
caseBlock.Statements.Add(new Branch(null, endBlock));
}
block.Statements.Add(new Branch(null, endBlock));
for( int i = 0, n = blocks.Count; i < n; i++ ) {
block.Statements.Add(blocks[i]);
}
block.Statements.Add(endBlock);
}
示例10: CreateTryCatchBlock
/// <summary>
/// Creates a block containing the given tryBlock and catchBlocks and
/// returns it. The method is modified by having new ExceptionHandlers
/// added to it which points to the right places in the blocks.
/// The type of exception caught by each catch block should be the type
/// of the corresponding local l.
/// </summary>
/// <param name="m">The method in which the try-catch block will be
/// inserted into.</param>
/// <param name="tryBody">A block of statements that will be the body
/// of the try-catch statement.</param>
/// <param name="catchBodies">A sequence of blocks; each one contains the
/// statements that will be the body of a catch clause on the try-catch statement.
/// </param>
/// <param name="l">The local into which the exception will be
/// assigned. Presumably, the body of the catch clause does something
/// with this local.</param>
/// <returns>A single block which must be inserted into m by the client.
/// </returns>
internal static Block CreateTryCatchBlock(Method m, Block tryBody, Block catchBody, Local l) {
BlockList bs = new BlockList(1);
bs.Add(catchBody);
LocalList ls = new LocalList(1);
ls.Add(l);
return CreateTryCatchBlock(m, tryBody, bs, ls);
}
示例11: WaveletTransform
public static List<double> WaveletTransform(List<double> serie)
{
//Declaring the blocks
var inputSeriesBlock = new InputSeriesBlock();
inputSeriesBlock.SetSeries(serie);
var dWTBlock = new DWTBlock
{
WaveletName = "coif4",
Level = 1,
Rescale = false,
ExtensionMode = SignalExtension.ExtensionMode.AntisymmetricWholePoint
};
var outputSeriesBlock = new OutputSeriesBlock();
//Connecting the blocks
inputSeriesBlock.OutputNodes[0].ConnectTo(dWTBlock.InputNodes[0]);
// dWTBlock.OutputNodes[1].ConnectTo(dWTBlock2.InputNodes[0]);
dWTBlock.OutputNodes[1].ConnectTo(outputSeriesBlock.InputNodes[0]);
//Appending the blocks to a block list and execute all
var blockList = new BlockList();
blockList.Add(inputSeriesBlock);
blockList.Add(dWTBlock);
//blockList.Add(dWTBlock2);
blockList.Add(outputSeriesBlock);
blockList.ExecuteAll();
return outputSeriesBlock.GetSeries();
}
示例12: ParseSwitchInstruction
private SwitchInstruction ParseSwitchInstruction()
{
int numTargets = this.GetInt32();
int offset = this.counter + numTargets * 4;
BlockList targetList = new BlockList();
for(int i = 0; i < numTargets; i++)
{
int targetAddress = this.GetInt32() + offset;
targetList.Add(Reader.GetOrCreateBlock(this.blockMap, targetAddress));
}
return new SwitchInstruction(PopOperand(), targetList);
}
示例13: AdjustBranches
/// <summary>
/// Called once after we handled all blocks (by MakeFlat)
/// </summary>
private void AdjustBranches()
{
for (int i = 0; i<this.branchInstructions.Count; i++)
{
Branch branch = (Branch)this.branchInstructions[i];
branch.Target = RemapBlock(branch.Target);
}
// Clone target list
for (int i = 0; i<this.switchInstructions.Count; i++)
{
SwitchInstruction sw = (SwitchInstruction)this.switchInstructions[i];
BlockList targets = sw.Targets;
BlockList newTargets = new BlockList(targets.Count);
sw.Targets = newTargets;
for (int j = 0; j<targets.Count; j++)
{
Block b = targets[j];
newTargets.Add(RemapBlock(b));
}
}
}
示例14: processOneSeries
private List<double> processOneSeries(List<double> serie)
{
//Declaring the blocks
var inputSeriesBlock = new InputSeriesBlock();
inputSeriesBlock.SetSeries(serie);
var dWTBlock = new DWTBlock
{
WaveletName = "Daubechies 10 (db10)",
Level = 1,
Rescale = false,
ExtensionMode = WaveletStudio.SignalExtension.ExtensionMode.AntisymmetricWholePoint
};
var outputSeriesBlock = new OutputSeriesBlock();
//Connecting the blocks
inputSeriesBlock.OutputNodes[0].ConnectTo(dWTBlock.InputNodes[0]);
dWTBlock.OutputNodes[1].ConnectTo(outputSeriesBlock.InputNodes[0]);
//Appending the blocks to a block list and execute all
var blockList = new BlockList();
blockList.Add(inputSeriesBlock);
blockList.Add(dWTBlock);
blockList.Add(outputSeriesBlock);
blockList.ExecuteAll();
return outputSeriesBlock.GetSeries();
}
示例15: VisitBlockList
public virtual Differences VisitBlockList(BlockList list1, BlockList list2,
out BlockList changes, out BlockList deletions, out BlockList insertions){
changes = list1 == null ? null : list1.Clone();
deletions = list1 == null ? null : list1.Clone();
insertions = list1 == null ? new BlockList() : list1.Clone();
//^ assert insertions != null;
Differences differences = new Differences();
for (int j = 0, n = list2 == null ? 0 : list2.Count; j < n; j++){
//^ assert list2 != null;
Block nd2 = list2[j];
if (nd2 == null) continue;
insertions.Add(null);
}
TrivialHashtable savedDifferencesMapFor = this.differencesMapFor;
this.differencesMapFor = null;
TrivialHashtable matchedNodes = new TrivialHashtable();
for (int i = 0, k = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
//^ assert list1 != null && changes != null && deletions != null;
Block nd1 = list1[i];
if (nd1 == null) continue;
Differences diff;
int j;
Block nd2 = this.GetClosestMatch(nd1, list1, list2, i, ref k, matchedNodes, out diff, out j);
if (nd2 == null || diff == null){Debug.Assert(nd2 == null && diff == null); continue;}
matchedNodes[nd1.UniqueKey] = nd1;
matchedNodes[nd2.UniqueKey] = nd2;
changes[i] = diff.Changes as Block;
deletions[i] = diff.Deletions as Block;
insertions[i] = diff.Insertions as Block;
insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation
Debug.Assert(diff.Changes == changes[i] && diff.Deletions == deletions[i] && diff.Insertions == insertions[i]);
differences.NumberOfDifferences += diff.NumberOfDifferences;
differences.NumberOfSimilarities += diff.NumberOfSimilarities;
}
//Find deletions
for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
//^ assert list1 != null && changes != null && deletions != null;
Block nd1 = list1[i];
if (nd1 == null) continue;
if (matchedNodes[nd1.UniqueKey] != null) continue;
changes[i] = null;
deletions[i] = nd1;
insertions[i] = null;
differences.NumberOfDifferences += 1;
}
//Find insertions
for (int j = 0, n = list1 == null ? 0 : list1.Count, m = list2 == null ? 0 : list2.Count; j < m; j++){
//^ assert list2 != null;
Block nd2 = list2[j];
if (nd2 == null) continue;
if (matchedNodes[nd2.UniqueKey] != null) continue;
insertions[n+j] = nd2; //Records nd2 as an insertion into list1, along with its position in list2
differences.NumberOfDifferences += 1; //REVIEW: put the size of the tree here?
}
if (differences.NumberOfDifferences == 0){
changes = null;
deletions = null;
insertions = null;
}
this.differencesMapFor = savedDifferencesMapFor;
return differences;
}