本文整理汇总了C#中System.Collections.BitArray.SetAll方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.SetAll方法的具体用法?C# BitArray.SetAll怎么用?C# BitArray.SetAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.BitArray
的用法示例。
在下文中一共展示了BitArray.SetAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BitArray_SetAllTest
public static void BitArray_SetAllTest()
{
BitArray ba2 = new BitArray(6, false);
Assert.False(ba2.Get(0)); //"Err_10! Expected ba4.Get(0) to be false"
Assert.False(ba2.Get(5)); //"Err_11! Expected ba4.Get(1) to be false"
// false to true
ba2.SetAll(true);
Assert.True(ba2.Get(0)); //"Err_12! Expected ba4.Get(0) to be true"
Assert.True(ba2.Get(5)); //"Err_13! Expected ba4.Get(1) to be true"
// false to false
ba2.SetAll(false);
Assert.False(ba2.Get(0)); //"Err_14! Expected ba4.Get(0) to be false"
Assert.False(ba2.Get(5)); //"Err_15! Expected ba4.Get(1) to be false"
ba2 = new BitArray(6, true);
Assert.True(ba2.Get(0)); //"Err_16! Expected ba4.Get(0) to be true"
Assert.True(ba2.Get(5)); //"Err_17! Expected ba4.Get(1) to be true"
// true to true
ba2.SetAll(true);
Assert.True(ba2.Get(0)); //"Err_18! Expected ba4.Get(0) to be true"
Assert.True(ba2.Get(5)); //"Err_19! Expected ba4.Get(1) to be true"
// true to false
ba2.SetAll(false);
Assert.False(ba2.Get(0)); //"Err_20! Expected ba4.Get(0) to be false"
Assert.False(ba2.Get(5)); //"Err_21! Expected ba4.Get(1) to be false"
// [] Size stress.
int size = 0x1000F;
ba2 = new BitArray(size, true);
Assert.True(ba2.Get(0)); //"Err_22! Expected ba4.Get(0) to be true"
Assert.True(ba2.Get(size - 1)); //"Err_23! Expected ba4.Get(size-1) to be true"
ba2.SetAll(false);
Assert.False(ba2.Get(0)); //"Err_24! Expected ba4.Get(0) to be false"
Assert.False(ba2.Get(size - 1)); //"Err_25! Expected ba4.Get(size-1) to be false"
}
示例2: CreateTree
private void CreateTree()
{
BitArray countIndices = new BitArray(recordCount);
countIndices.SetAll(true);
Varset empty = new Varset(network.Size());
root = MakeADTree(0, countIndices, 0, empty);
}
示例3: SocketCommandsStream
public SocketCommandsStream(TextReader reader, TextWriter writer)
{
_sockerReader = reader;
_socketWriter = writer;
_commandRun = new BitArray((int)CommandMap.Commands.Help + 1);
_commandRun.SetAll(false);
}
示例4: next_ServerClick
protected void next_ServerClick(object sender, EventArgs e)
{
user u = new user();
u.user_id = (int)Session["id"];
u = os.getUserById(u);
int seat_num = (int)Session["seat_num"];
o.SSR = this.SSR.Value ;
o.type = type;
FlightService fs = new FlightService();
String plane_type_name = searchF.plane.plane_type.name;
BitArray seat = new BitArray(20);
seat.SetAll(false);
seat.Set(seat_num,true);
o.seat = OrderService.BitArrayToByteArray(seat);
if ( (o = os.generate(u, searchF, o, seat_num)) != null)
{
Session["new_order"] = o;
Server.Transfer("payment.aspx");
}
else
{
ShowPopUpMsg("Seat is book by others!");
}
}
示例5: Length
public void Length()
{
var ba = new BitArray(32);
ba.SetAll(true);
ba.Length = 16;
Assert.Equal(16, ba.Length);
}
示例6: GeneratePrimes
private static IEnumerable<int> GeneratePrimes(int topCandidate)
{
var sieve = new BitArray(topCandidate + 1);
/* Set all but 0 and 1 to prime status */
sieve.SetAll(true);
sieve[0] = sieve[1] = false;
/* Mark all the non-primes */
var thisFactor = 2;
while (thisFactor * thisFactor <= topCandidate)
{
/* Mark the multiples of this factor */
int mark = thisFactor + thisFactor;
while (mark <= topCandidate)
{
sieve[mark] = false;
mark += thisFactor;
}
/* Set thisfactor to next prime */
thisFactor++;
while (!sieve[thisFactor]) { thisFactor++; }
}
for (int i = 0; i < sieve.Length; i++)
{
if (sieve[i]) yield return i;
}
}
示例7: Allocator
public Allocator()
{
int n = 10;
m_bits = new BitArray(n);
m_bits.SetAll(false);
m_bytes = new Byte[(n - 1) / 8 + 1];
}
示例8: Main
static void Main(string[] args)
{
var input = int.Parse(Console.ReadLine());
var arr = new BitArray(input + 1);
arr.SetAll(true);
var highestPrime = GeneratePrimes(arr, input);
Console.WriteLine(highestPrime);
}
示例9: Node
public Node()
{
attrCount = Globals.attrCount;
availableAttrs = new BitArray(attrCount);
availableAttrs.SetAll(true);
availableAttrs.Set(attrCount-1, false);
tuples = new List<Tuple>();
childNodes = new List<Node>();
}
示例10: Main
static void Main()
{
//input
int arraySize = int.Parse(Console.ReadLine());
//get array
int[] toSearch = new int[arraySize];
for (int i = 0; i < arraySize; i++)
{
toSearch[i] = int.Parse(Console.ReadLine());
}
// variables
BitArray sumFlags = new BitArray(arraySize);
BitArray maxFlags = new BitArray(arraySize);
int curSum = 0;
int maxSum = toSearch.Sum();
for (int curNumb = 0; curNumb < toSearch.Length; curNumb++)
{
// Step 1: Get Current Sum
curSum += toSearch[curNumb];
sumFlags.Set(curNumb, true);
if (curSum > maxSum)
{
// Store the Sum
maxSum = curSum;
// Flag the indexes
maxFlags.SetAll(false);
maxFlags.Or(sumFlags);
}
else
{
if (curSum < 0)
{
// discard and start summing again
curSum = 0;
sumFlags.SetAll(false);
}
else
{
// keep going
continue;
}
}
}
// output
Console.WriteLine(maxSum);
}
示例11: BitArrayTest
//BitArrayTest
public static void BitArrayTest()
{
var tmp = new BitArray(8);
var tmp1 = new BitArray(8);
tmp1.SetAll(true);
tmp.SetAll(false);
foreach(bool tm in tmp)
{
Console.WriteLine(tm);
}
foreach (bool tm in tmp1)
{
Console.WriteLine(tm);
}
Console.WriteLine();
}
示例12: BitArrayDemo
static void BitArrayDemo()
{
var bits1 = new BitArray(8);
bits1.SetAll(true);
bits1.Set(1, false);
bits1[5] = false;
bits1[7] = false;
Console.Write("initialized: ");
DisplayBits(bits1);
Console.WriteLine();
DisplayBits(bits1);
bits1.Not();
Console.Write(" not ");
DisplayBits(bits1);
Console.WriteLine();
var bits2 = new BitArray(bits1);
bits2[0] = true;
bits2[1] = false;
bits2[4] = true;
DisplayBits(bits1);
Console.Write(" or ");
DisplayBits(bits2);
Console.Write(" : ");
bits1.Or(bits2);
DisplayBits(bits1);
Console.WriteLine();
DisplayBits(bits2);
Console.Write(" and ");
DisplayBits(bits1);
Console.Write(" : ");
bits2.And(bits1);
DisplayBits(bits2);
Console.WriteLine();
DisplayBits(bits1);
Console.Write(" xor ");
DisplayBits(bits2);
bits1.Xor(bits2);
Console.Write(" : ");
DisplayBits(bits1);
Console.WriteLine();
}
示例13: BSieve
private static string BSieve(BitArray bArray)
{
bArray.SetAll(true);
bArray[0] = bArray[1] = false; //clever ;-) -> These wont be considered prime numbers
for (int i = 2; i < bArray.Length; i++)
//this iterations goes through and finds true values inside of the passed bit array
{
if (bArray[i]) //if true then the next iteration happens
{
for (int k = 2; (i*k) < bArray.Length; k++)
/*this iteration creates multiples of the prime
number and sets thos multiples int the bit array to false */
{
bArray[(i*k)] = false;
}
}
}
var primeStringOutput = new StringBuilder(); //string variable
ushort quickCounter = 0; //a quick counter variable
for (int i = 0; i < bArray.Length; i++) //this iteration creates the string
{
if (bArray[i]) //if true then increase the quick counter and append the main output string
{
primeStringOutput.Append(i.ToString());
quickCounter++;
if (quickCounter == 7)
{
primeStringOutput.Append("\n");
quickCounter = 0;
} //if true then create a new line and reset the counter
else
{
primeStringOutput.Append("\t");
}
; //else just tab each numeric character
}
}
return primeStringOutput.ToString(); //returns string at very end
}
示例14: ComputePrimes
public static void ComputePrimes(int limit)
{
// Sieve of Erathosthenes
primes = new BitArray(limit);
primes.SetAll(true);
primes.Set(0, false);
primes.Set(1, false);
for (int i = 0; i * i < limit; i++)
{
if (primes.Get(i))
{
for (int j = i * i; j < limit; j += i)
{
primes.Set(j, false);
}
}
}
}
示例15: RTSBuilding
// Constructor
public RTSBuilding(RTSTeam team, RTSBuildingData data, Vector2 position)
{
// Identification
UUID = UUIDGenerator.GetUUID();
Team = team;
gridPos = position;
viewedInfo = new BitArray(GameState.MAX_PLAYERS);
viewedInfo.SetAll(false);
Data = data;
gridPos.X += (Data.GridSize.X - 1);
gridPos.Y += (Data.GridSize.Y - 1);
height = 0;
Health = Data.Health;
bAmount = Data.BuildAmount;
CollisionGeometry = Data.ICollidableShape.Clone() as ICollidable;
ViewDirection = Vector2.UnitX;
CollisionGeometry.Center += GridPosition;
bControllers = new List<ACBuildingButtonController>();
}