Class LinqDataCalcExtensions
- Namespace
- LinqDataCalc
- Assembly
- LinqDataCalc.dll
Main LinqDataCalcExtensions Class implementation.
public static class LinqDataCalcExtensions
- Inheritance
-
LinqDataCalcExtensions
- Inherited Members
Methods
AsNumberTuples(IEnumerable<object>)
Retrieve a list of numeric tuples from an input list of objects.
public static IList<Tuple<int, ulong, long, double, decimal>> AsNumberTuples(this IEnumerable<object> elements)
Parameters
elements
IEnumerable<object>The list of objects to be used as input
Returns
- IList<Tuple<int, ulong, long, double, decimal>>
A list of tuples with the relevant data types retrieved from the objects list
Examples
Get a List of zero-filled Tuples with numeric values (int/ulong/long/double/decimal).
object[] types = { "###","hello1","!*",439,30,12,1.3,3.2m,new List{1,3,5,78,14,24,40,9},'d',3283782378289,"2902",92.4m,"345,2",881.74m,30333.1434,-43902,(new int[]{10,490,20,103,40,30}),930 };
var resTuple = types.AsNumberTuples();
BTreeGen(double, int)
Generate a binary tree of random height, based on a prespecified complexity factor value (needs to be of double data type).
public static LinqDataCalcExtensions.Node BTreeGen(this double nodeDensity, int depth)
Parameters
nodeDensity
doubleThe density factor of which to generate the random tree nodes with
depth
intThe b-tree depth for which to determine the height with
Returns
- LinqDataCalcExtensions.Node
A randomly generated b-tree root with leaf nodes that consist of Node data type
Examples
Generate a binary tree of specified depth N with random nodes density.
var tree_root = 0.543.BTreeGen(6);
BTreeGen2(int, double)
Generate a range of binary trees of random height, based on a prespecified complexity factor value (needs to be of double data type) and yields an enumerable based on those b-trees.
public static IEnumerable<LinqDataCalcExtensions.Node> BTreeGen2(int depth, double nodeDensity)
Parameters
depth
intThe b-tree depth for which to determine the height with
nodeDensity
doubleThe density factor of which to generate the random tree nodes with
Returns
- IEnumerable<LinqDataCalcExtensions.Node>
An IEnumerable of multiple b-tree roots with random leaf nodes that consist of Node data type
Examples
Generate a binary tree range of specified depth N with random nodes density.
var ienum_tree_roots = LinqDataCalcExtensions.BTreeGen2(3,0.75);
BTreeHeight(Node)
Calculation of a b-tree total height counting edges from the root node, to the end of the leafs of the data structure. (Utilizes queuing on adding/removing nodes for height calculation)
public static int BTreeHeight(this LinqDataCalcExtensions.Node input)
Parameters
input
LinqDataCalcExtensions.NodeThe root node of the b-tree of which to calculate the height from.
Returns
- int
Calculated b-tree data structure height (root node = start).
Examples
Calculate the b-tree height from the root node to outer leafs.
var tree_root = 0.543.BTreeGen(6); //creates a root b-tree of size 6
LinqDataCalcExtensions.BTreeHeight(tree_root); // result of total height 5
ChunkOf<T>(IEnumerable<T>, int)
Retrieves chunks of size N from a list as a nested list.
public static IEnumerable<IEnumerable<T>> ChunkOf<T>(this IEnumerable<T> elements, int len)
Parameters
elements
IEnumerable<T>List of elements used as input
len
intLength of N - chunks that the elements list is to be splitted into
Returns
- IEnumerable<IEnumerable<T>>
A nested enumerable list of which sub lists are chunks of equal length
Type Parameters
T
Any type of elements in the list
Examples
Split an IEnumerable into chunks of Length N.
int[] num_seq = { -990,-940,-770,-599,-543,-513,-482,-451,-445,-371,-240,-371,-940 };
var num = num_seq.AsEnumerable();
var result = num.ChunkOf(3);
CompareBytes(byte[], byte[])
Compare the bytes in two 1-dimensional byte arrays.
public static bool CompareBytes(this byte[] larray, byte[] rarray)
Parameters
Returns
- bool
True or False depending on the result
Examples
Check whether two 1-dimensional byte arrays are equal.
byte[] b1 = new byte[]{77,90,144,0,3,0,0,0,4,0,0,0,255,255,0,0,184,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,14,31,32,100};
byte[] b2 = new byte[]{77,90,144,0,3,0,0,0,4,0,0,0,255,20,0,0,0,0,0,0,128,0,0,0,14,31,186,14,0,180,9,205,33,184,1,76,103,114};
bool result = b1.CompareBytes(b2);
DictionaryRndFill(Dictionary<string, Tuple<int, int>>, int)
Retrieve a dictionary with random integer numbers and a randomly produced string.
public static IDictionary<string, Tuple<int, int>> DictionaryRndFill(this Dictionary<string, Tuple<int, int>> dictionary, int length)
Parameters
Returns
- IDictionary<string, Tuple<int, int>>
A dictionary of key=string/value=Tuple(int,int) type layout filled with random values
Examples
Get an IDictionary filled with string keys and corresponding integer random values.
// 1 - full code not shown.. Initialize a dictionary of key-value type key=string/value=Tuple(int,int)
//2 - call following method of the dictionary -> dict_var.DictionaryRndFill(10);
DiffBytes(byte[], byte[])
Checks two 1-dimensional byte arrays and returns a list of the positions where the bytes are different with the byte values.
public static IDictionary<int, int> DiffBytes(this byte[] mainarr, byte[] diffarr)
Parameters
mainarr
byte[]The main byte array to be compared
diffarr
byte[]The secondary byte array to be compared against
Returns
- IDictionary<int, int>
An Dictionary with the different bytes and the array positions that contains the difference against.
Examples
Check two 1-dimensional byte arrays, and return a list of different bytes and the point of difference.
byte[] b1 = new byte[]{77,90,144,0,3,0,0,0,4,0,0,0,255,255,0,0,184,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,14,31,32,100};
byte[] b2 = new byte[]{77,90,144,0,3,0,0,0,4,0,0,0,255,20,0,0,0,0,0,0,128,0,0,0,14,31,186,14,0,180,9,205,33,184,1,76,103,114};
var result = b1.DiffBytes(b2);
ExpectedValue(IEnumerable<double>, IEnumerable<double>)
Based on a number list of probability values and a secondary list of possible expected outcomes of that probability, retrieve the overall expected value of the frequency of occurence on the inital observation/event.
public static double ExpectedValue(this IEnumerable<double> probabilities, IEnumerable<double> outcomes)
Parameters
probabilities
IEnumerable<double>List of probability values
outcomes
IEnumerable<double>List of expected outcome values
Returns
- double
The expected outcome/frequency of occurence value
Examples
Calculates Expected value of two probability sequences.
double expected = new double[]{1,2,3,4,5,6,7,8}.ExpectedValue(Enumerable.Repeat(0.125,8));
Factorial(IEnumerable<int>)
Calculates the factorial of any given value, from a provided range of values.
public static IEnumerable<int> Factorial(this IEnumerable<int> values)
Parameters
values
IEnumerable<int>List of input values
Returns
- IEnumerable<int>
The list of factorials based on their original values
Examples
Calculates Factorial values for an IEnumerable.
var result = Enumerable.Range(1,10).Factorial();
FiboSeq(int)
Fibonacci sequence for a given number as input.
public static IEnumerable<ulong> FiboSeq(this int numLimit)
Parameters
numLimit
intThe max number that fibonacci seq. gets generated for
Returns
- IEnumerable<ulong>
An IEnumerable with fibonacci numbers.
Examples
Get the resulting numeric fibonacci sequence.
var seq_out = 10.FiboSeq();
var seq_out = 100.FiboSeq();
FiboSeqGenerator(int)
Fibonacci sequence yield utilizing generator functions.
public static IEnumerable<ulong> FiboSeqGenerator(this int num)
Parameters
num
intThe max number that fibonacci seq. gets generated for
Returns
- IEnumerable<ulong>
An IEnumerable with large fibonacci numbers.
Examples
Get the resulting numeric fibonacci sequence.
var seq_out = 10.FiboSeqGenerator();
var seq_out = 100.FiboSeqGenerator();
GetRandomElements<T>(IEnumerable<T>, int)
Retrieve a list of random elements from an input list.
public static IEnumerable<T> GetRandomElements<T>(this IEnumerable<T> elements, int totElements)
Parameters
elements
IEnumerable<T>The list of elements to be used as input
totElements
intThe maximum number of random elements to be retrieved
Returns
- IEnumerable<T>
A list of random elements with specified total length
Type Parameters
T
Any type of elements in the list
Examples
Get an IEnumerable of 10 randomly selected elements.
var tenElements = Enumerable.Range(1,100).GetRandomElements(10);
HammingDist(string, string)
Hamming distance calculation for comparing two strings of equal length Retrieves the different characters count in both strings
public static int HammingDist(this string leftStr, string rightStr)
Parameters
Returns
- int
Maximum integer value in case both strings are not equal in legth, Number of differences in both strings otherwise.
Examples
Retrieve a default value as result if strings are not equal or hamming comparison value.
int res = "ABCDHFGF".HammingDist("ABCDEFO9"); //res equals to 3
int res = "ABC".HammingDist("AAABBBCCCDD77"); //res equals to MaxInt
int res = "A8udhhG".HammingDist("A8udhhG"); //res equals to 0
int res = "A8udhhG".HammingDist("A8UDHHG"); //res equals to 4
HammingDistAlgo(int, int, AlgoType)
Hamming Distance calculation between two integer numbers using different algorithm variants, multiple algo. selections. (Calculated bit-level differences between numerical values)
public static int HammingDistAlgo(this int leftNum, int rightNum, LinqDataCalcExtensions.AlgoType hamming_alg)
Parameters
leftNum
intThe leftmost number to compare with
rightNum
intThe rightmost number to be compared with
hamming_alg
LinqDataCalcExtensions.AlgoTypeThe hamming distance algorithm selection Can only use: AlgoType.DistLoop, AlgoType.DistXOR1, AlgoType.DistXOR2 for setting appropriate variant to use.
Returns
Examples
Calculating the hamming distance between two integers by using different methods.
int res = (-995).HammingDistAlgo((-48),LinqDataCalcExtensions.AlgoType.DistXOR1);
int res = (-995).HammingDistAlgo((-48),LinqDataCalcExtensions.AlgoType.DistXOR2);
int res = (-995).HammingDistAlgo((-48),LinqDataCalcExtensions.AlgoType.DistLoop);
//Result in all cases above = 7
HammingWeight(uint)
Hamming Weight Calculation for bit-depth of integers (UInt support of 32-bit integer values) Utilizes direct "bit manipulation, bit swapping" algorithm for hamming weight calculation.
public static int HammingWeight(this uint in_x)
Parameters
in_x
uintThe integer value to return the numerical weight for
Returns
- int
The calculated integer value of hamming weight
Examples
Calculate the resulting hamming weight of an integer value.
uint testVal = 0x10043091; //int values
int result = testVal.HammingWeight();
HammingWeight(ulong)
Hamming Weight Calculation for bit-depth of long integers (ULong support of 64-bit integer values) Utilizes direct "bit manipulation, bit swapping" algorithm for hamming weight calculation.
public static int HammingWeight(this ulong in_x)
Parameters
in_x
ulongThe long integer value to return the numerical weight for
Returns
- int
The calculated integer value of hamming weight
Examples
Calculate the resulting hamming weight of a long integer value.
ulong testVal = 0x8891930311; //large int values
int result = testVal.HammingWeight();
HappySeq(int)
For a provided maximum value, generate happy numbers sequence up to that value.
public static IEnumerable<int> HappySeq(this int endLimit)
Parameters
endLimit
intThe numeric sequence upper limit to generate the happy numbers for
Returns
- IEnumerable<int>
A list of integer numbers.
Examples
Get the integers in a sequence that produce a happy sum.
var list_out = 150.HappySeq();
var list_out = 10.HappySeq();
var list_out = 0.HappySeq(); //list_out Length = 0
var list_out = 1.HappySeq(); //list_out Length = 1 (value = 1)
IEnumRndFill(IEnumerable<int>, object)
Retrieve a list with random integer or decimal numbers depending on input provided.
public static IEnumerable<object> IEnumRndFill(this IEnumerable<int> retIntSeq, object number)
Parameters
retIntSeq
IEnumerable<int>The list used as input
number
objectA numeric value, decimal or integer
Returns
- IEnumerable<object>
A list of random values
Examples
Get an IEnumerable filled with random integer/double values.
var resultInt = Enumerable.Repeat(0,10).IEnumRndFill(5); // fills with random integers
var resultDouble = Enumerable.Repeat(0,10).IEnumRndFill(1.5); // fills with random doubles
IterateAt<T>(IEnumerable<T>, int)
Retrieves a range of values from a list iteratively as a nested list. Element list at index 1 at indexes 1,2 at 1,2,3 up to N.
public static IEnumerable<IEnumerable<T>> IterateAt<T>(this IEnumerable<T> elements, int size)
Parameters
elements
IEnumerable<T>List of elements used as input
size
intNumber of max iterations that lists are retrieved
Returns
- IEnumerable<IEnumerable<T>>
A nested enumerable list that has a maximum length defined by -size- parameter
Type Parameters
T
Any type of elements in the list
Examples
Get the Nth iteration of an IEnumerable in nested form.
int[] num_seq = { -990,-940,-770,-599,-543,-513,-482,-451,-445,-371,-240,-371,-940 };
var num = num_seq.AsEnumerable();
var result = num.IterateAt(4);
LetterCombinationsOf(string)
Retrieve all letter combinations (power sets) of a provided string.
public static List<string> LetterCombinationsOf(this string strElement)
Parameters
strElement
stringThe string of letters used as input
Returns
Examples
Get a List of strings displaying letter combinations.
var combinations = ("He1l01!").LetterCombinationsOf();
LevnDist(string, string)
Levenshtein distance for two input strings and edit differences for those. (Can be applied between two strings of equal or differing length in size)
public static int LevnDist(this string strLeft, string strRight)
Parameters
strLeft
stringThe leftmost string to find edit diffs from
strRight
stringThe rightmost string to compare edit diffs with
Returns
- int
Calculated sum or edit distance per input set of strings as integer.
Examples
Calculate the levenshtein distance between strings left, right.
int result = "Paints".LevnDist("ants"); //result = 2
int result = "Compute".LevnDist("Confuse"); // result = 3
LevnDistEditMatrix(string, string)
Levenshtein edit distance matrix retrieval with full set of calculations. (Can be applied between two strings of equal or differing length in size)
public static IEnumerable<int[,]> LevnDistEditMatrix(this string str1, string str2)
Parameters
str1
stringThe leftmost string to compare edit diffs from
str2
stringThe rightmost string to compare edit diffs with
Returns
- IEnumerable<int[,]>
An enumerable of the entire 2-dimensional edit distances matrix with all distance calculations.
Examples
Calculate the levenshtein distance of two strings, return the entire set of iterations, element at array position [N,M] is the result of the total diff distance.
var result_ienum = "test2".LevnDistEditMatrix("arst22"); //last matrix element = 3
var result_ienum = "ant".LevnDistEditMatrix("aunt"); //last matrix element = 1
LevnDistRecur(string, string, int[,])
A recursive Levenstein implementation utilizing memoized cache for faster execution time. (Can be applied between two strings of equal or differing length in size)
public static int LevnDistRecur(this string leftStrIn, string rightStrIn, int[,] memo)
Parameters
leftStrIn
stringThe leftmost string to find edit diffs from
rightStrIn
stringThe rightmost string to compare edit diffs with
memo
int[,]The matrix to store the intermediary distance cost results in Note: Needs to be the same size as NxM such that N = length of leftStrIn, M = length of rightStrIn
Returns
- int
Calculated sum or edit distance per input set of strings as integer.
Examples
Calculate the levenshtein distance between strings left, right.
int result = "test2".LevnDistRecur("arst22",new int[("test2".Length)+1,("arst22".Length)+1]); // result = 3
int result = "Sam".LevnDistRecur("Samantha",new int[("Sam".Length)+1,("Samantha".Length)+1]); // result = 5
MatrixProduct(int[,], int[,])
Matrix dot product calculation for 2-dimensional integer arrays of shape NxM. (PLINQ utilization for large data sets handling)
public static int[,] MatrixProduct(this int[,] matrixA, int[,] matrixB)
Parameters
matrixA
int[,]First integer matrix to be used for multipl. product
matrixB
int[,]Second integer matrix to be multiplied with for multipl. product
Returns
- int[,]
The product matrix in a 2-dimensional matrix format
Examples
Calculate and retrieve the dot product of multiplying the two input matrices.
var result = new int[4,2]{{2,2},{3,7},{8,4},{8,5}}.MatrixProduct(new int[2,3]{{1,2,4},{12,42,9}}); // Result as a 2-dim array
MatrixProductv2(int[,], int[,], int)
Matrix dot product calculation for 2-dimensional integer arrays of shape NxM. (Outputs the finalized product matrix in either list of lists or standard 2-d array format)
public static object MatrixProductv2(this int[,] mtrx1, int[,] mtrx2, int twoDim = 0)
Parameters
mtrx1
int[,]First integer matrix to be used for multipl. product
mtrx2
int[,]Second integer matrix to be multiplied with for multipl. product
twoDim
intSelection option to retrieve the product result as a list of sublists or as a normal 2-dimensional matrix
Returns
- object
An Object of either List of sublists type or int[,] type that defines product matrix result.
Examples
Calculate and retrieve the dot product of multiplying two matrices in both list-of-lists format or standard 2-dimensional array format. This can be determined by a variable, defaults to 2-dimensional array output.
var result_1 = new int[4,2]{{2,2},{3,7},{8,4},{8,5}}.MatrixProductv2(new int[2,3]{{1,2,4},{12,42,9}},0); // Results to 2-dim array output
var result_2 = new int[4,2]{{2,2},{3,7},{8,4},{8,5}}.MatrixProductv2(new int[2,3]{{1,2,4},{12,42,9}},1); // Results to list of lists output
MatrixTranspose<T>(T[,])
Transposes a 2-dimensional array of different data type such that rows N become columns M and vice-versa.
public static T[,] MatrixTranspose<T>(this T[,] matrixIn)
Parameters
matrixIn
T[,]The 2-dimensional input matrix to invert rows with columns from
Returns
- T[,]
Transposed 2-dimensional matrix of the original input array for any kind of array elements.
Type Parameters
T
Any kind of elements in a sequence
Examples
Transpose 2-dimensional matrix of dimensions [N,M].
int[,] matrixT1 = new int[6,2] { {3,4},{5,9},{10,44},{3,77},{88,0},{0,90} }; //test with integers matrix
double[,] matrixT2 = new double[5,9]{ {9.0,34.0,0.99,3.1,9.4,4.51,9.87,1.43,9.88}, {2.4,22.01,55.10,9.09,1.30,9.99,10.45,9.0,8.01},
{4.6,4.3,3.4,68.009,45.92,3.54,9.89,5.69,0.849},{1.2,4.5,33.5,54.4,45.9,5.89,9.09,1.223,4.54},
{4.5,1.0,4,42.9,9.9,9.9,9,9,9} }; //test with doubles matrix
var resultT1 = matrixT1.MatrixTranspose(); // results in a 2x6 matrix
var resultT2 = matrixT2.MatrixTranspose(); // results in a 9x5 matrix
MatrixTranspose<T>(T[][])
Transposes a 2-dimensional jagged -or uneven- array of different data type such that rows N become columns M and vice-versa.
public static T[][] MatrixTranspose<T>(this T[][] matrixIn)
Parameters
matrixIn
T[][]The 2-dimensional jagged array to invert rows with columns from
Returns
- T[][]
Transposed 2-dimensional jagged array of the original input array for any kind of array elements.
Type Parameters
T
Any kind of elements in a sequence
Examples
Transposed 2-dimensional jagged array of dimensions [N][M].
string[][] matrixT3 = new string[][]{ //test with strings array
new string[12]{"This", "is a", "test","this","side","should","appear","on the left","of ","your","screen","if the"},
new string[12]{" script"," has ","been run ","as", " expected.","Test ","run"," already ","for a ","matrix of ","nxm size "," where n is" },
new string[12]{"equal to 3"," and ","m equal"," to "," twelve"," If n"," and m","increase"," or decrease then","output should","vary ","accordingly"}
};
var resultT3 = matrixT3.MatrixTranspose(); //results in a 12x3 jagged array [12][3]
MaxCollVals(List<List<int>>, bool)
Retrieve either the maximum or minimum set of value from every nested integer list-of-lists data structure.
public static List<int> MaxCollVals(this List<List<int>> inputColl, bool isMax = true)
Parameters
inputColl
List<List<int>>Input nested list to retrieve max-min set of values from
isMax
boolOption to retrieve either the maximum or minimum values per subset in every list-of-lists dataset
Returns
- List<int>
An integer list containing the maximum value of each column-compared subset in list-of lists
Examples
Retrieve all the maximum, or minimum integer values for each column-based subset in the input nested list.
// 1 - Provided that you initialize a list of lists (code not shown..)
// . . .
allValues.Add(valuesSet1); // 2 - populate the lists of lists
allValues.Add(valuesSet2);
allValues.Add(valuesSet3);
allValues.Add(valuesSet4);
var result = allValues.MaxCollVals(); //defaults to maximum subset of values for every column-compared subset of lists
var result = allValues.MaxCollVals(false); //results to minimum subset of values for every column-compared subset of lists
MaxMatrixVal(int[,], bool)
Retrieve either the maximum or minimum value in a 2-dimensional integer matrix.
public static int MaxMatrixVal(this int[,] mtrx, bool isMax = true)
Parameters
mtrx
int[,]Input matrix to retrieve max-min values from
isMax
boolOption to retrieve either the maximum or minimum value from 2-dimensional dataset from
Returns
- int
The maximum or minimum integer value of the input matrix
Examples
Retrieve the maximum, or minimum integer value from the input matrix.
int[,] arr2d = new int[,]{{10,40,13,40},{9,10,40,99},{9,10,40,99},{9,10,49,19},{9,10,40,990},{9,10,422,99}};
var result = arr2d.MaxMatrixVal() // defaults to maximum value = 990
var result = arr2d.MaxMatrixVal(false) // retrieve minimum value = 9
MaxMultiDimVal(int[][], bool)
Retrieve either the maximum or minimum value in a jagged array data structure.
public static int MaxMultiDimVal(this int[][] mtrx, bool isMax = true)
Parameters
mtrx
int[][]Input matrix to retrieve max-min values from
isMax
boolOption to retrieve either the maximum or minimum value from the jagged array dataset
Returns
- int
The maximum or minimum integer value of the input array of arrays
Examples
Retrieve the maximum, or minimum integer value from the input array of arrays.
int[] arr1 = new int[] {1,2,3,5,4};
int[] arr2 = new int[] {3,2,1,0,10,39,10,43,11};
int[] arr3 = new int[]{24,1,90};
int[][] main_arr = new int[][]{arr1,arr2,arr3};
var result = main_arr.MaxMultiDimVal() // defaults to maximum value = 90
var result = main_arr.MaxMultiDimVal(false) // retrieve minimum value = 0
MedianValue(IEnumerable<int>)
Return the median value in an -ordered- numeric sequence.
public static double MedianValue(this IEnumerable<int> elements)
Parameters
elements
IEnumerable<int>The numeric sequence used as input
Returns
- double
Double median value for the selected sequence
Examples
Get the median value in an IEnumerable.
int[] num_seq = { -990,-940,-770,-599,-543,-513,-482,-451,-445,-371,-240 };
var num = num_seq.AsEnumerable();
double result = num.MedianValue();
ModeValues(IEnumerable<int>)
Retrieve the mode values in a sequence of numbers. (The most frequently occuring number - ordered)
public static IEnumerable<KeyValuePair<int, int>> ModeValues(this IEnumerable<int> elements)
Parameters
elements
IEnumerable<int>The numeric sequence used as input
Returns
- IEnumerable<KeyValuePair<int, int>>
An IEnumerable KeyValuePair with Key=total per the mode value and Value=occuring value in the sequence.
Examples
Get the top used values in an IEnumerable.
int[] num_seq = { -990,-940,-770,-599,-543,-513,-482,-451,-445,-371,-240,-371,-940 };
var num = num_seq.AsEnumerable();
var result = num.ModeValues();
OddOrEven<T>(IEnumerable<T>)
Checks whether the total length of a sequence is odd or even.
public static bool OddOrEven<T>(this IEnumerable<T> elements)
Parameters
elements
IEnumerable<T>The data sequence to be checked
Returns
- bool
True or False depending on the result
Type Parameters
T
Any kind of elements in a sequence
Examples
Check whether length of IEnumerable is odd or even.
bool oddlen = new int[]{4,43,13,50,40}.OddOrEven();
PowerOf(int, int)
Raises a number to the Nth power recursively.
public static int PowerOf(this int value, int powBy)
Parameters
Returns
- int
Result of the power of a number
Examples
Calculates Nth power of an integer.
int result = new int[]{4,43,13,50,40}.Select(n=>n.PowerOf(3));
ReorderElementsIterator<T>(IEnumerable<T>, Random)
Implementation of the iterative functionality for the list reording.
public static IEnumerable<T> ReorderElementsIterator<T>(this IEnumerable<T> elements, Random prng)
Parameters
elements
IEnumerable<T>The list of elements to be used as input
prng
RandomThe Random object to be used as seed for shuffling indexes
Returns
- IEnumerable<T>
A list of reordered elements using random index shuffling in the initial list
Type Parameters
T
Any type of elements in the list
ReorderElements<T>(IEnumerable<T>)
Retrieve a list of random elements from an input list -using natural reordering-.
public static IEnumerable<T> ReorderElements<T>(this IEnumerable<T> elements)
Parameters
elements
IEnumerable<T>
Returns
- IEnumerable<T>
A reording elements iterator result with the Random object seed
Type Parameters
T
Any type of elements in the list
Examples
Get an IEnumerable of 10 reordered elements.
var tenElements = Enumerable.Range(1,10).ReorderElements().Take(10);
RndDoubleTuple(IEnumerable<int>, double)
Provided a list of integer values you, retrieve a list of tuples and random doubles with random string values.
public static IList<(double sample, string name)> RndDoubleTuple(this IEnumerable<int> elements, double scaleFact)
Parameters
elements
IEnumerable<int>A list of default integers to be modified
scaleFact
doubleThe scaling factor by which double values are created
Returns
Examples
Get a List Tuple filled with random doubles and random strings.
var resRndDouble = Enumerable.Range(1,10).RndDoubleTuple(.001);
Remarks
This works using argument deconstruction by ValueTuple type (available with C# >= 7, .NET >= 4.7, VS 2019) Already included .dll reference for ValueTuples (currently .NET = 4.6.)
RndIntTuple(IEnumerable<int>)
Provided a list of integer values you, retrieve a list of tuples and random integer with random string values.
public static IList<(int sample, string name)> RndIntTuple(this IEnumerable<int> elements)
Parameters
elements
IEnumerable<int>A list of default integers to be modified
Returns
Examples
Get an List Tuple filled with random integers and random strings.
var resRndInt = Enumerable.Range(1,10).RndIntTuple();
Remarks
This works using argument deconstruction by ValueTuple type (available with C# >= 7, .NET >= 4.7, VS 2019) Already included .dll reference for ValueTuples (currently .NET = 4.6.)
SequenceEquals<T>(T[,], T[,])
Checks whether two 2-dimensional arrays of any element type are equal.
public static bool SequenceEquals<T>(this T[,] a, T[,] b)
Parameters
a
T[,]The first sequence to be compared
b
T[,]The second sequence to be compared against the first
Returns
- bool
True or False depending on the result
Type Parameters
T
Any kind of elements in a sequence
Examples
Check whether two 2-dimensinonal arrays of any type are equal.
int[,] intArray1 = new int[4,4]{{432,31,32,43},{324,321,55,31},{110,34,543,13},{90,321,453,12}};
int[,] intArray2 = new int[4,4]{{110,43,120,301},{54,312,321,91},{99,45,21,12},{9,32,45,152}};
bool res = intArray1.SequenceEquals(intArray2);
byte[,] barray1 = new byte[3,3]{{132,56,32},{30,45,10},{92,100,48}};
byte[,] barray2 = new byte[3,3]{{132,56,32},{30,45,10},{92,100,48}};
bool res = barray1.SequenceEquals(barray2);
StandardDeviation(IEnumerable<double>)
Calculates the standard deviation value of double numeric sequence.
public static double StandardDeviation(this IEnumerable<double> values)
Parameters
values
IEnumerable<double>The numeric sequence used as input
Returns
- double
Standard deviation double result
Examples
Calculates STDEVP() for long.
double result = new long[]{394392,93993,323993,49240,49329}.StandardDeviation();
StandardDeviation(IEnumerable<int>)
Calculates the standard deviation value of integer numeric sequence.
public static double StandardDeviation(this IEnumerable<int> values)
Parameters
values
IEnumerable<int>The numeric sequence used as input
Returns
- double
Standard deviation double result
Examples
Calculates STDEVP().
double result = new int[]{10,23,13,50,4}.StandardDeviation();
StandardDeviation(IEnumerable<long>)
Calculates the standard deviation value of large integer numeric sequence.
public static double StandardDeviation(this IEnumerable<long> values)
Parameters
values
IEnumerable<long>The numeric sequence used as input
Returns
- double
Standard deviation double result
Examples
Calculates STDEVP() for doubles.
double result = new double[]{0.1124,2.311,4.11,2.94,5.51).StandardDeviation();
TenPowerOf(int)
Returns the value of 10 raised to the power of N value.
public static object TenPowerOf(this int powOf)
Parameters
powOf
intThe Nth power value
Returns
- object
Result of the 10 in the power of N (can be float,int,ulong)
Examples
Calculates Nth power of number 10.
long tenthousand = (4).TenPowerOf();
Remarks
The function will not output negative values
ToDoublePowerOf(IEnumerable<int>, double)
Raises each number in a sequence to the Nth power(where N is double).
public static IEnumerable<double> ToDoublePowerOf(this IEnumerable<int> values, double val)
Parameters
values
IEnumerable<int>The list of integers to be raised to the Nth double power
val
doubleThe Nth power double value
Returns
- IEnumerable<double>
Resulting list of double values raised to the Nth power
Examples
Calculates Nth double power of all integers in IEnumerable.
int[] num_seq = { -990,-940,-770,-599,-543,-513,-482,-451,-445,-371,-240,-371,-940 };
var num = num_seq.AsEnumerable();
var result = num.ToDoublePowerOff(2.71);
ToIntMatrix(string, int[,])
Present a sequence of numbers in a string, into a 2-dimensional matrix (letters and some characters are ommited) that has zero-fill for extra positions in case that array is larger than input.
public static int[,] ToIntMatrix(this string StrNum, int[,] twodimOut)
Parameters
StrNum
stringThe string of numbers to be used as input
twodimOut
int[,]The 2d matrix to be used as output
Returns
- int[,]
A 2-dimensional integer matrix, of prespecified dimensions N x M
Examples
Retrieve ONLY numbers from a string represented in a 2d matrix array. Note: Minimum array dimensions are 2x2 (used as default when input length less than 4 or when overallocating array space).
int[,] result = "2911".ToIntMatrix(new int[4,4]); // Result OK with zero padding
int[,] result = "2962728abcs1119__1".ToIntMatrix(new int[4,10]); //Result OK with zero padding
int[,] result = "2962728abcs1119__1".ToIntMatrix(new int[4,2]); //Result OK, trimmed
int[,] result = "2962728abcs1119__1".ToIntMatrix(new int[4,3]); //Result OK
int[,] result = "2962728abcs1119__1".ToIntMatrix(new int[10,10]); //Result n/a, trimmed to 2x2 with zero padding
int[,] result = "29".ToIntMatrix(new int[1,2]); //Result n/a, trimmed to 2x2 with zero padding
ToIntPowerOf(IEnumerable<int>, int)
Raises each number in a sequence to the Nth power.
public static IEnumerable<long> ToIntPowerOf(this IEnumerable<int> values, int val)
Parameters
values
IEnumerable<int>The list of integers to be raised to the Nth power
val
intThe Nth power value
Returns
- IEnumerable<long>
Resulting list of large integers raised to the Nth power
Examples
Calculates Nth power of all integers in IEnumerable.
int[] num_seq = { -990,-940,-770,-599,-543,-513,-482,-451,-445,-371,-240,-371,-940 };
var num = num_seq.AsEnumerable();
var result = num.ToIntPowerOf(3);
VectorProduct(int[], int[])
Calculation of the dot product for integer vectors N -vector multiplication-
public static IEnumerable<int> VectorProduct(this int[] v1, int[] v2)
Parameters
v1
int[]First integer array vector to multiply values from
v2
int[]Second integer array vectr to multiply values with
Returns
- IEnumerable<int>
An integer IEnumerable containing the dot product values based on the initial vectors
Examples
Calculate and retrieve the dot product of multiplying two vectors as an IEnumerable.
int[] vect1 = {2,3,3}; // First vector
int[] vect2 = {3,2,2}; // Second vector
var result = vect1.VectorProduct(vect2); // result is an IEnumerable list of multipl. values
add(int, int)
Binary addition of two integer numbers incl. carry digits. (negative or positive integer numerical values only)
public static int add(this int from_x, int add_y)
Parameters
from_x
intNumerical value x to perform the addition to
add_y
intNumerical value y to use in addition operation
Returns
- int
The integer result of the addition operation
Examples
Retrieve the result of adding integer y to underlying value x or vice-versa.
int result1 = 100.add(93);
int result2 = -90.add(54);
subtract(int, int)
Binary subtraction of two integer numbers incl. carry digits. (negative or positive integer numerical values only)
public static int subtract(this int from_x, int sub_y)
Parameters
from_x
intNumerical value x to perform the subtraction from
sub_y
intNumerical value y to use in subtraction operation
Returns
- int
The integer result of the subtraction operation
Examples
Retrieve the result of subtracting integer y from underlying value x or vice-versa.
int result = -483.subtract(53);
int result = -483.subtract(403);