Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,48 @@
using System;
using System.Collections.Specialized;

public class SamplesBitVector32 {
public class SamplesBitVector32
{

public static void Main() {
public static void Main()
{

// Creates and initializes a BitVector32.
BitVector32 myBV = new BitVector32( 0 );
// Creates and initializes a BitVector32.
BitVector32 myBV = new(0);

// Creates four sections in the BitVector32 with maximum values 6, 3, 1, and 15.
// mySect3, which uses exactly one bit, can also be used as a bit flag.
BitVector32.Section mySect1 = BitVector32.CreateSection( 6 );
BitVector32.Section mySect2 = BitVector32.CreateSection( 3, mySect1 );
BitVector32.Section mySect3 = BitVector32.CreateSection( 1, mySect2 );
BitVector32.Section mySect4 = BitVector32.CreateSection( 15, mySect3 );
// Creates four sections in the BitVector32 with maximum values 6, 3, 1, and 15.
// mySect3, which uses exactly one bit, can also be used as a bit flag.
BitVector32.Section mySect1 = BitVector32.CreateSection(6);
BitVector32.Section mySect2 = BitVector32.CreateSection(3, mySect1);
BitVector32.Section mySect3 = BitVector32.CreateSection(1, mySect2);
BitVector32.Section mySect4 = BitVector32.CreateSection(15, mySect3);

// Displays the values of the sections.
Console.WriteLine( "Initial values:" );
Console.WriteLine( "\tmySect1: {0}", myBV[mySect1] );
Console.WriteLine( "\tmySect2: {0}", myBV[mySect2] );
Console.WriteLine( "\tmySect3: {0}", myBV[mySect3] );
Console.WriteLine( "\tmySect4: {0}", myBV[mySect4] );
// Displays the values of the sections.
Console.WriteLine("Initial values:");
Console.WriteLine($"\tmySect1: {myBV[mySect1]}");
Console.WriteLine($"\tmySect2: {myBV[mySect2]}");
Console.WriteLine($"\tmySect3: {myBV[mySect3]}");
Console.WriteLine($"\tmySect4: {myBV[mySect4]}");

// Sets each section to a new value and displays the value of the BitVector32 at each step.
Console.WriteLine( "Changing the values of each section:" );
Console.WriteLine( "\tInitial: \t{0}", myBV.ToString() );
myBV[mySect1] = 5;
Console.WriteLine( "\tmySect1 = 5:\t{0}", myBV.ToString() );
myBV[mySect2] = 3;
Console.WriteLine( "\tmySect2 = 3:\t{0}", myBV.ToString() );
myBV[mySect3] = 1;
Console.WriteLine( "\tmySect3 = 1:\t{0}", myBV.ToString() );
myBV[mySect4] = 9;
Console.WriteLine( "\tmySect4 = 9:\t{0}", myBV.ToString() );
// Sets each section to a new value and displays the value of the BitVector32 at each step.
Console.WriteLine("Changing the values of each section:");
Console.WriteLine($"\tInitial: \t{myBV}");
myBV[mySect1] = 5;
Console.WriteLine($"\tmySect1 = 5:\t{myBV}");
myBV[mySect2] = 3;
Console.WriteLine($"\tmySect2 = 3:\t{myBV}");
myBV[mySect3] = 1;
Console.WriteLine($"\tmySect3 = 1:\t{myBV}");
myBV[mySect4] = 9;
Console.WriteLine($"\tmySect4 = 9:\t{myBV}");

// Displays the values of the sections.
Console.WriteLine( "New values:" );
Console.WriteLine( "\tmySect1: {0}", myBV[mySect1] );
Console.WriteLine( "\tmySect2: {0}", myBV[mySect2] );
Console.WriteLine( "\tmySect3: {0}", myBV[mySect3] );
Console.WriteLine( "\tmySect4: {0}", myBV[mySect4] );
}
// Displays the values of the sections.
Console.WriteLine("New values:");
Console.WriteLine($"\tmySect1: {myBV[mySect1]}");
Console.WriteLine($"\tmySect2: {myBV[mySect2]}");
Console.WriteLine($"\tmySect3: {myBV[mySect3]}");
Console.WriteLine($"\tmySect4: {myBV[mySect4]}");
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@
using System;
using System.Collections.Specialized;

public class SamplesBitVector32 {

public static void Main() {

// Creates and initializes a BitVector32 with all bit flags set to FALSE.
BitVector32 myBV = new BitVector32( 0 );

// Creates masks to isolate each of the first five bit flags.
int myBit1 = BitVector32.CreateMask();
int myBit2 = BitVector32.CreateMask( myBit1 );
int myBit3 = BitVector32.CreateMask( myBit2 );
int myBit4 = BitVector32.CreateMask( myBit3 );
int myBit5 = BitVector32.CreateMask( myBit4 );
Console.WriteLine( "Initial: \t{0}", myBV.ToString() );

// Sets the third bit to TRUE.
myBV[myBit3] = true;
Console.WriteLine( "myBit3 = TRUE \t{0}", myBV.ToString() );

// Combines two masks to access multiple bits at a time.
myBV[myBit4 + myBit5] = true;
Console.WriteLine( "myBit4 + myBit5 = TRUE \t{0}", myBV.ToString() );
myBV[myBit1 | myBit2] = true;
Console.WriteLine( "myBit1 | myBit2 = TRUE \t{0}", myBV.ToString() );
}
public class SamplesBitVector32
{

public static void Main()
{

// Creates and initializes a BitVector32 with all bit flags set to FALSE.
BitVector32 myBV = new(0);

// Creates masks to isolate each of the first five bit flags.
int myBit1 = BitVector32.CreateMask();
int myBit2 = BitVector32.CreateMask(myBit1);
int myBit3 = BitVector32.CreateMask(myBit2);
int myBit4 = BitVector32.CreateMask(myBit3);
int myBit5 = BitVector32.CreateMask(myBit4);
Console.WriteLine($"Initial: \t{myBV}");

// Sets the third bit to TRUE.
myBV[myBit3] = true;
Console.WriteLine($"myBit3 = TRUE \t{myBV}");

// Combines two masks to access multiple bits at a time.
myBV[myBit4 + myBit5] = true;
Console.WriteLine($"myBit4 + myBit5 = TRUE \t{myBV}");
myBV[myBit1 | myBit2] = true;
Console.WriteLine($"myBit1 | myBit2 = TRUE \t{myBV}");
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,59 @@
using System;
using System.Collections.Specialized;

public class SamplesBitVector32 {
public class SamplesBitVector32
{

public static void Main() {
public static void Main()
{

// Creates and initializes a BitVector32 with the value 123.
// This is the BitVector32 that will be compared to different types.
BitVector32 myBV = new BitVector32( 123 );
// Creates and initializes a BitVector32 with the value 123.
// This is the BitVector32 that will be compared to different types.
BitVector32 myBV = new(123);

// Creates and initializes a new BitVector32 which will be set up as sections.
BitVector32 myBVsect = new BitVector32( 0 );
// Creates and initializes a new BitVector32 which will be set up as sections.
BitVector32 myBVsect = new(0);

// Compares myBV and myBVsect.
Console.WriteLine( "myBV : {0}", myBV.ToString() );
Console.WriteLine( "myBVsect : {0}", myBVsect.ToString() );
if ( myBV.Equals( myBVsect ) )
Console.WriteLine( " myBV({0}) equals myBVsect({1}).", myBV.Data, myBVsect.Data );
else
Console.WriteLine( " myBV({0}) does not equal myBVsect({1}).", myBV.Data, myBVsect.Data );
Console.WriteLine();
// Compares myBV and myBVsect.
Console.WriteLine($"myBV : {myBV}");
Console.WriteLine($"myBVsect : {myBVsect}");
if (myBV.Equals(myBVsect))
Console.WriteLine($" myBV({myBV.Data}) equals myBVsect({myBVsect.Data}).");
else
Console.WriteLine($" myBV({myBV.Data}) does not equal myBVsect({myBVsect.Data}).");
Console.WriteLine();

// Assigns values to the sections of myBVsect.
BitVector32.Section mySect1 = BitVector32.CreateSection( 5 );
BitVector32.Section mySect2 = BitVector32.CreateSection( 1, mySect1 );
BitVector32.Section mySect3 = BitVector32.CreateSection( 20, mySect2 );
myBVsect[mySect1] = 3;
myBVsect[mySect2] = 1;
myBVsect[mySect3] = 7;
// Assigns values to the sections of myBVsect.
BitVector32.Section mySect1 = BitVector32.CreateSection(5);
BitVector32.Section mySect2 = BitVector32.CreateSection(1, mySect1);
BitVector32.Section mySect3 = BitVector32.CreateSection(20, mySect2);
myBVsect[mySect1] = 3;
myBVsect[mySect2] = 1;
myBVsect[mySect3] = 7;

// Compares myBV and myBVsect.
Console.WriteLine( "myBV : {0}", myBV.ToString() );
Console.WriteLine( "myBVsect with values : {0}", myBVsect.ToString() );
if ( myBV.Equals( myBVsect ) )
Console.WriteLine( " myBV({0}) equals myBVsect({1}).", myBV.Data, myBVsect.Data );
else
Console.WriteLine( " myBV({0}) does not equal myBVsect({1}).", myBV.Data, myBVsect.Data );
Console.WriteLine();
// Compares myBV and myBVsect.
Console.WriteLine($"myBV : {myBV}");
Console.WriteLine($"myBVsect with values : {myBVsect}");
if (myBV.Equals(myBVsect))
Console.WriteLine($" myBV({myBV.Data}) equals myBVsect({myBVsect.Data}).");
else
Console.WriteLine($" myBV({myBV.Data}) does not equal myBVsect({myBVsect.Data}).");
Console.WriteLine();

// Compare myBV with an Int32.
Console.WriteLine( "Comparing myBV with an Int32: " );
Int32 myInt32 = 123;
// Using Equals will fail because Int32 is not compatible with BitVector32.
if ( myBV.Equals( myInt32 ) )
Console.WriteLine( " Using BitVector32.Equals, myBV({0}) equals myInt32({1}).", myBV.Data, myInt32 );
else
Console.WriteLine( " Using BitVector32.Equals, myBV({0}) does not equal myInt32({1}).", myBV.Data, myInt32 );
// To compare a BitVector32 with an Int32, use the "==" operator.
if ( myBV.Data == myInt32 )
Console.WriteLine( " Using the \"==\" operator, myBV.Data({0}) equals myInt32({1}).", myBV.Data, myInt32 );
else
Console.WriteLine( " Using the \"==\" operator, myBV.Data({0}) does not equal myInt32({1}).", myBV.Data, myInt32 );
}
// Compare myBV with an Int32.
Console.WriteLine("Comparing myBV with an Int32: ");
int myInt32 = 123;
// Using Equals will fail because Int32 is not compatible with BitVector32.
if (myBV.Equals(myInt32))
Console.WriteLine($" Using BitVector32.Equals, myBV({myBV.Data}) equals myInt32({myInt32}).");
else
Console.WriteLine($" Using BitVector32.Equals, myBV({myBV.Data}) does not equal myInt32({myInt32}).");
// To compare a BitVector32 with an Int32, use the "==" operator.
if (myBV.Data == myInt32)
Console.WriteLine($" Using the \"==\" operator, myBV.Data({myBV.Data}) equals myInt32({myInt32}).");
else
Console.WriteLine($" Using the \"==\" operator, myBV.Data({myBV.Data}) does not equal myInt32({myInt32}).");
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@
using System;
using System.Collections.Specialized;

public class SamplesBitVector32 {

public static void Main() {

// Creates and initializes a BitVector32 with all bit flags set to FALSE.
BitVector32 myBV = new BitVector32( 0 );

// Creates masks to isolate each of the first five bit flags.
int myBit1 = BitVector32.CreateMask();
int myBit2 = BitVector32.CreateMask( myBit1 );
int myBit3 = BitVector32.CreateMask( myBit2 );
int myBit4 = BitVector32.CreateMask( myBit3 );
int myBit5 = BitVector32.CreateMask( myBit4 );

// Sets the alternating bits to TRUE.
Console.WriteLine( "Setting alternating bits to TRUE:" );
Console.WriteLine( " Initial: {0}", myBV.ToString() );
myBV[myBit1] = true;
Console.WriteLine( " myBit1 = TRUE: {0}", myBV.ToString() );
myBV[myBit3] = true;
Console.WriteLine( " myBit3 = TRUE: {0}", myBV.ToString() );
myBV[myBit5] = true;
Console.WriteLine( " myBit5 = TRUE: {0}", myBV.ToString() );
}
public class SamplesBitVector32
{

public static void Main()
{

// Creates and initializes a BitVector32 with all bit flags set to FALSE.
BitVector32 myBV = new(0);

// Creates masks to isolate each of the first five bit flags.
int myBit1 = BitVector32.CreateMask();
int myBit2 = BitVector32.CreateMask(myBit1);
int myBit3 = BitVector32.CreateMask(myBit2);
int myBit4 = BitVector32.CreateMask(myBit3);
int myBit5 = BitVector32.CreateMask(myBit4);

// Sets the alternating bits to TRUE.
Console.WriteLine("Setting alternating bits to TRUE:");
Console.WriteLine($" Initial: {myBV}");
myBV[myBit1] = true;
Console.WriteLine($" myBit1 = TRUE: {myBV}");
myBV[myBit3] = true;
Console.WriteLine($" myBit3 = TRUE: {myBV}");
myBV[myBit5] = true;
Console.WriteLine($" myBit5 = TRUE: {myBV}");
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ public static void Main()

// Select cities from the table using mixed case.
Console.WriteLine("Case insensitive hashtable results:\n");
Console.WriteLine("{0}'s population is: {1}", "Trapperville", population1["trapperville"]);
Console.WriteLine("{0}'s population is: {1}", "Doggerton", population1["DOGGERTON"]);
Console.WriteLine("{0}'s population is: {1}", "New Hollow", population1["New hoLLow"]);
Console.WriteLine("{0}'s population is: {1}", "McHenry", population1["MchenrY"]);
Console.WriteLine($"{"Trapperville"}'s population is: {population1["trapperville"]}");
Console.WriteLine($"{"Doggerton"}'s population is: {population1["DOGGERTON"]}");
Console.WriteLine($"{"New Hollow"}'s population is: {population1["New hoLLow"]}");
Console.WriteLine($"{"McHenry"}'s population is: {population1["MchenrY"]}");

SortedList population2 = CollectionsUtil.CreateCaseInsensitiveSortedList();

foreach (string city in population1.Keys)
{
population2.Add(city, population1[city]);
population2.Add(city, population1[city]);
}

// Select cities from the sorted list using mixed case.
Console.WriteLine("\nCase insensitive sorted list results:\n");
Console.WriteLine("{0}'s population is: {1}", "Trapperville", population2["trapPeRVille"]);
Console.WriteLine("{0}'s population is: {1}", "Doggerton", population2["dOGGeRtON"]);
Console.WriteLine("{0}'s population is: {1}", "New Hollow", population2["nEW hOLLOW"]);
Console.WriteLine("{0}'s population is: {1}", "McHenry", population2["MchEnrY"]);
Console.WriteLine($"{"Trapperville"}'s population is: {population2["trapPeRVille"]}");
Console.WriteLine($"{"Doggerton"}'s population is: {population2["dOGGeRtON"]}");
Console.WriteLine($"{"New Hollow"}'s population is: {population2["nEW hOLLOW"]}");
Console.WriteLine($"{"McHenry"}'s population is: {population2["MchEnrY"]}");
}
}

// This program displays the following output to the console
// This program displays the following output to the console.
//
// Case insensitive hashtable results:
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

Expand Down
Loading
Loading