My Project
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
AronLib.h File Reference

This is AronLib.h. More...

#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <utility>
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include "Vector3.h"
#include "DDLinkedList.h"
#include "Const.h"
#include "/Users/aaa/myfile/bitbucket/clib/AronCLibNew.h"
#include <vector>
#include "glm/glm/glm.hpp"
#include <dirent.h>
#include <unistd.h>
#include <limits.h>
#include <regex>
#include <algorithm>
#include <cctype>
#include <locale>
#include <limits>
#include <stdexcept>
#include <array>
#include <boost/filesystem.hpp>

Go to the source code of this file.

Classes

class  StopWatch
 
class  two< T, U >
 
class  AronGeometry::Point< T >
 
class  AronGeometry::Pair< T >
 
class  AronGeometry::Vector< T >
 
class  AronGeometry::Segment< T >
 
class  SpaceComplex::Complex
 
class  MatrixVector::vec
 
class  MatrixVector::row
 
class  MatrixVector::mat
 
class  MatrixVector::mat::Loader
 Inspired from Eigen Lib. More...
 
class  SpaceVector4::Vector4
 

Namespaces

namespace  Utility
 many function can be global actually
 
namespace  Complex
 complex number representation and operation number
 
namespace  MatrixVector
 Two dimensional array represents matrix, column and row vector.
 
namespace  SpaceVector4
 4 dimensions vector
 
namespace  Algorithm
 include all the sorting algorithms etc.
 

Functions

int len (string s)
 length of string
 
template<typename T >
int len (vector< T > v)
 length of vector
 
template<typename T >
string toStr (const T &s)
 Convert any type to std::string.
 
template<typename T >
string toStr2 (T &s)
 
template<typename T >
string toStrVar (T &s)
 
template<typename T >
vector< vector< T > > transpose (vector< vector< T > > mat)
 transpose matrix
 
template<typename T >
bool compareVector (vector< T > v1, vector< T > v2)
 
template<typename T >
bool compareVector (vector< vector< T > > v1, vector< vector< T > > v2)
 
template<typename T >
vector< vector< T > > arrToVec2 (T *arr, int len, int width)
 
void printArr2 (float *arr, int len, int width)
 
int unsignToInt (size_t u)
 
string padRight (string s, string pad, int maxLen)
 
string padLeft (string s, string pad, int maxLen)
 
template<typename T >
two< T, T > divMod (T a, T b)
 
void newline ()
 
void nl ()
 
int max (int a, int b, int c)
 
int max (int a, int b, int c, int d)
 
int max (vector< int > v)
 
string reverseStr (string s)
 
int maxConsecutiveOne (vector< int > vec)
 
int strToInt (string s)
 
int numFromBase (string fromBase, string input)
 
vector< int > range (int a, int b)
 
vector< int > range (int a, int b, int stride)
 
template<typename T >
vector< T > reverseVec (vector< T > vec)
 
std::map< char, int > hexMap ()
 
string baseToBase (string fromBase, string toBase, string input)
 
uint64_t nowMilliseconds ()
 
uint64_t nowMicroseconds ()
 
uint64_t nowNanoseconds ()
 
template<typename T >
vector< T > repeatVec (int n, T t)
 
template<typename T >
vector< T > concatVec (vector< T > v1, vector< T > v2)
 Concat two vectors.
 
vector< int > randomNanoSec (int n, int max)
 
template<typename T >
dotProduct (vector< T > v1, vector< T > v2)
 
template<typename T >
det2 (vector< vector< T > > v2)
 
template<typename T >
vector< T > subtract (vector< T > v1, vector< T > v2)
 
void testfun ()
 
void testfun1 ()
 
void testfun2 ()
 
void getTypeSize ()
 
int maxConsecutiveChar (char *arr, int size, char c)
 
std::map< int, char > hexMapRev ()
 
vector< int > toBinary (int n)
 
int abs_int (int a)
 
float abs_f (float a)
 
long abs_l (long a)
 
long long abs_ll (long long a)
 
double abs_d (double a)
 
unsigned int abs_ui (unsigned int a)
 
template<typename T >
void writeFileAppendVector (string fname, std::vector< T > vec)
 
void writeFile (string fname, string s)
 
void writeFileAppend (string fname, string s)
 
template<typename T >
void writeFileVector (string fname, std::vector< T > vec)
 
template<typename T >
void writeFileAppendRow (string fname, std::vector< T > vec)
 Write vector to file using space as delimiter.
 
std::pair< string, string > split (string s, int inx)
 
vector< int > sumVec (vector< int > v1, vector< int > v2)
 sum two int vectors
 
string removeIndex (string s, int inx)
 remove char from a string
 
template<typename T >
vector< T > removeIndex (vector< T > &vec, int inx)
 remove an index from a vector
 
template<typename T >
vector< T > removeIndexRange (vector< T > &vec, int fromInx, int toInx)
 remove index from to index inclusively.
 
string repeat (int n, string s)
 Repeating n copy of s. The function is inspired by Haskell repeat.
 
string cStringToString (const char *pt)
 char* to string
 
template<typename T >
void pl (T t)
 
void print (glm::vec3 v3)
 
void print (glm::vec2 v2)
 
string removeAdjacentDuplicateChar (string s, char c)
 remove adjacent duplicate char from a string
 
string concatValidPath (vector< string > vec)
 remove adjacent duplicate char from a string
 
template<typename T >
void print (std::pair< T, T > pair)
 
template<typename T >
void print (vector< T > vec)
 
template<typename T >
void printVec (vector< T > vec)
 
template<typename T >
void print (vector< vector< T > > vec)
 
template<typename T >
void print (T t)
 
template<typename T >
void print (string msg, T t)
 
template<typename T >
void printLnNb (T t)
 
template<typename T >
vector< T > operator+ (vector< T > v1, vector< T > v2)
 Concate two vectors, both vectors are NOT modified.
 
string operator+ (const char *chars, string s)
 
string operator+ (string s, const char *chars)
 
template<typename T >
vector< T > con (T t, vector< T > v)
 
void AronPrint::ppf (const char *format,...)
 
void AronPrint::fw (string s)
 
template<typename T >
void AronPrint::pp (T t)
 
template<typename T >
void AronPrint::pp (T t1, T t2)
 
template<typename T >
void AronPrint::pp (T t1, T t2, T t3)
 
template<typename T , typename U >
void AronPrint::pp (std::pair< T, U > p)
 
void AronPrint::pp (int n)
 
void AronPrint::pp (float n)
 
void AronPrint::pp (long n)
 
void AronPrint::pp (unsigned long n)
 
void AronPrint::pp (string msg0, string msg1)
 
void AronPrint::pp (string msg0, float num)
 
void AronPrint::pp (string msg0, int num)
 
void AronPrint::pp (string msg0, long num)
 
void AronPrint::pp (string msg0, double num)
 
void AronPrint::pp (string msg0, char *charPt)
 
void AronPrint::fl (string s)
 
template<typename T >
AronLambda::head (vector< T > vec)
 
char AronLambda::head (string s)
 
template<typename T >
AronLambda::last (vector< T > vec)
 
template<typename T >
void swap (vector< T > &vec, int i, int j)
 
int random (int n)
 random number from 0 to n-1 NOTE: Ubuntu DOES NOT have arc4random_uniform, it works on MacOS only.
 
template<typename T >
void swap (T arr[], int i, int j)
 
long lcgRandom (long x0)
 Linear congruential generator.
 
vector< int > randomIntVec (int count, int max)
 
vector< int > allPrime (int n)
 
vector< int > * nPrime (int n)
 
const char * stringToCString (string s)
 Convert std::string to char*, same as s2c(string s)
 
const char * s2c (string s)
 Convert std::string to char*.
 
const char * toCharPtr (string s)
 it is same as s2c but it is better name.
 
const char * strToCharArray (string s)
 
template<typename T , typename U >
string toStr (std::pair< T, U > p)
 
template<typename T , typename U >
string str (std::pair< T, U > p)
 
template<typename T >
string str (const T &s)
 
template<typename T >
string str2 (T &s)
 
string trimLeft (string str)
 
string trimRight (string str)
 
string trim (string str)
 trim both ends
 
string charPtrToString (const char *pt)
 
string c2s (const char *pt)
 string to char*
 
bool containStrRegex (string s, regex rx)
 check s contains regex pattern
 
bool containStr (string str, string pat)
 check if str contain pat
 
vector< string > splitStr (string s, string delim)
 Split string with delimiter.
 
template<typename T >
std::pair< vector< T >, vector< T > > splitAt (int n, vector< T > vec)
 split vector to pair of vector
 
template<typename Fun , typename T >
std::pair< vector< T >, vector< T > > breakVec (Fun f, vector< T > vec)
 break a vector to pair
 
template<typename T >
vector< T > replaceVec (T oldVal, T newVal, vector< T > vec)
 replace oldVale with newVal in a cloned vector
 
template<typename T >
vector< T > insertAt (vector< T > vec, int pos, vector< T > insertVec)
 Insert vector @insertVec into vec at position @pos.
 
vector< std::string > splitStrRegex (const string &s, string rgxStr="\\s+")
 Split string with regex.
 
bool isEmpty (string s)
 
bool isEmpty (const char *cpt)
 
double squareRoot (double a)
 
double intToDouble (int n)
 
double nthRoot (double c, int n, double epsilon=0.000001)
 Compute the nth root of any positive integer, n >= 1.
 
string charArrToString (const char *pt)
 
string replicate (int n, string s)
 
template<typename T >
void add (vector< T > &vec, T t)
 
int compareCString (char *s1, char *s2)
 
int compareString (string s1, string s2)
 
bool compareFloat (double a, double b)
 
void printLn (glm::vec3 v3)
 
void printLn (glm::vec2 v2)
 
string toString (glm::vec3 v3)
 
int inx (int cIx, int rIx, int width)
 
void tranmat4 (float arr[16])
 
template<typename T >
bool compareArray (T arr1[], T arr2[], const int s1)
 
template<typename T >
void print (two< T, T > t)
 
template<typename T >
void printNb (T t)
 print no bracket
 
template<typename T >
void printLn (T t)
 
template<typename T >
void ppL (T t)
 
void printArr (float arr[10], int n, int nCol)
 
template<typename T >
vector< T > * moveVec (T a, vector< T > vec)
 use std::move, it acts like Java. Create local object, and return it.
 
template<typename T >
vector< T > * append (vector< T > vec, T a)
 use std::move, it acts like Java. Create local object, and return it.
 
int length (string s)
 length of string
 
template<typename T >
int length (vector< T > v)
 length of vector
 
template<typename T >
bool binSearch (T key, T arr[], int lo, int hi)
 binary search on a sorted array
 
template<typename T >
vector< T > operator* (T a, vector< T > vec)
 scalar multiply vector
 
template<typename T >
vector< T > operator* (vector< T > vec, T a)
 scalar multiply vector
 
template<typename T >
vector< vector< T > > operator* (T a, vector< vector< T > > vec2)
 
template<typename T >
vector< vector< T > > operator* (vector< vector< T > > vec2, T a)
 
vector< int > geneVector (int a, int b)
 
bool isBST (Node< int > *curr, Node< int > *&prev)
 Check whether a Binary Tree is BST.
 
template<typename T >
vector< vector< T > > geneMatrix (int ncol, int nrow, T init)
 Generate ncol x nrow matrix with initial value @init.
 
template<typename T >
void swapT (T array[], int i, int j)
 
template<typename T >
int partitionT (T array[], int lo, int hi)
 partition array inline
 
template<typename T >
partition (vector< T > &vec, int lo, int hi)
 partition vector, use [hi] as pivot, like in quicksort
 
template<typename T >
int partitionInline (vector< T > &vec, int lo, int hi)
 partition vector inline
 
template<typename T >
void quickSortVec (vector< T > &vec, int lo, int hi)
 
template<typename T >
void quickSortT (T array[], int lo, int hi)
 
std::string replace (std::string str, regex rex, std::string rep)
 
bool isEmptyLine (string s)
 
string getEnv (string env)
 
template<typename T >
vector< T > getCol (int ix, vector< vector< T > > v)
 
template<class T = double>
double AronGeometry::isColinear3 (Point< T > p, Point< T > p1, Point< T > p2)
 
template<class T = double>
bool AronGeometry::isCrossSegment (Point< T > p0, Point< T > p1)
 
bool Utility::isSubstring (string sub, string s)
 Check whether sub is the substring of s.
 
int Utility::substringFirstIndex (string sub, string s)
 find the index of sub in string s
 
string Utility::fun_parent_parent ()
 
void Utility::cut (char *pt)
 
int Utility::stringToInt (string s)
 
double Utility::stringToDouble (std::string s)
 
long Utility::stringToLong (std::string s)
 
float Utility::stringToFloat (std::string s)
 
string Utility::charToString (char ch)
 
void Utility::begin ()
 
void Utility::begin (const char *name)
 
void Utility::end ()
 
string Utility::fun_parent ()
 
void Utility::print (Vector3 v)
 
void Utility::print (DDLinkedList< Vector3 > *ddl)
 
Complex SpaceComplex::rectangular (std::pair< double, double > p)
 
template<typename T >
T ** MatrixVector::allocateTemp (int ncol, int nrow)
 Allocate ncol, nrow two dimension array for any type, return a pointer.
 
template<typename T >
T ** MatrixVector::allocate (int ncol, int nrow)
 Allocate a matrix: height = ncol, width = nrow.
 
template<typename T >
T ** MatrixVector::vecVecToArrArr (vector< vector< T > > vv)
 Convert Vector< Vector<T> > to dynamic T**.
 
template<typename T >
vector< vector< T > > MatrixVector::arrArrToVecVec (T **arr, int ncol, int nrow)
 Convert T** arr to vector<vector<T>> v2.
 
mat MatrixVector::concat (mat m1, mat m2)
 
mat MatrixVector::identity (int n)
 
vec MatrixVector::backwardSubstitute (mat a, vec b)
 Backward Substitute.
 
mat MatrixVector::ltri (mat m, int index)
 Get the L triangle from a matrix.
 
std::pair< mat, matMatrixVector::utri (mat m)
 Assume the diagonal entries are not zero, compute the U triangle matrix Lk..(L2 (L1 A))= U TODO: fix the code if a_{ii} = 0.
 
mat MatrixVector::geneMat (int ncol, int nrow, int init)
 
mat MatrixVector::geneMatRandom (int ncol, int nrow, int fst, int snd)
 Generate random matrix in interval from fst to snd.
 
void Algorithm::merge (int *arr, int lo, int mid, int hi)
 
void Algorithm::mergeSort (int *arr, int lo, int hi)
 
void Algorithm::swap (int array[], int i, int j)
 
int Algorithm::partition (int array[], int lo, int hi)
 partition array to to left and right, using [hi] as pivot
 
void Algorithm::quickSortArr (int array[], int lo, int hi)
 
void writeFile (string fname, mat &m)
 
template<class T >
det2 (vector< T > v1, vector< T > v2)
 
template<class T >
vector< T > crossProduct (vector< T > v1, vector< T > v2)
 

Detailed Description

This is AronLib.h.


include it in your code: #include "AronLib.h"

g++ -I$HOME/cpplib

Function Documentation

◆ append()

template<typename T >
vector< T > * append ( vector< T >  vec,
a 
)

use std::move, it acts like Java. Create local object, and return it.

 Better name

◆ binSearch()

template<typename T >
bool binSearch ( key,
arr[],
int  lo,
int  hi 
)

binary search on a sorted array

k = 4 1 1 2 2 4 x 2 4 x 4 t

◆ breakVec()

template<typename Fun , typename T >
std::pair< vector< T >, vector< T > > breakVec ( Fun  f,
vector< T >  vec 
)

break a vector to pair

◆ compareCString()

int compareCString ( char *  s1,
char *  s2 
)

compare char* char* return n < 0, n == 0, n > 0

◆ compareFloat()

bool compareFloat ( double  a,
double  b 
)

compare float float

◆ compareString()

int compareString ( string  s1,
string  s2 
)

compare string string return n < 0, n == 0, n > 0

◆ concatValidPath()

string concatValidPath ( vector< string >  vec)

remove adjacent duplicate char from a string

vec = {"a", "/b", "c"};
concatValidPath(vec) => a/b/c
string concatValidPath(vector< string > vec)
remove adjacent duplicate char from a string
Definition: AronLib.h:2510

LINE: concatValidPath({"a", "b"}) => a/b

vec = {"a", "/b", "c"};
concatValidPath(vec) => a/b/c

LINE: concatValidPath({"a", "b"}) => a/b

◆ containStr()

bool containStr ( string  str,
string  pat 
)

check if str contain pat

containStr("dog file.x", "file\\.x") => true
match test with string
bool containStr(string str, string pat)
check if str contain pat
Definition: AronLib.h:1599

◆ containStrRegex()

bool containStrRegex ( string  s,
regex  rx 
)

check s contains regex pattern

#include <regex>
regex rx("[a-z]+");
containStrRegex("dog cat", rx); => true
bool containStrRegex(string s, regex rx)
check s contains regex pattern
Definition: AronLib.h:1584

◆ crossProduct()

template<class T >
vector< T > crossProduct ( vector< T >  v1,
vector< T >  v2 
)

KEY: cross product of two vectors

Cofactor expension

v1 = x0 y0 z0

v2 = x1 y1 z1

i j k x0 y0 z0 x1 y1 z1

v1 ⨂ v2 = (-1)^1+1 i |y0 z0| |y1 z1| + (-1)^1+2 j |x0 z0| |x1 z1| + (-1)^1+3 k |x0 y0| |x1 y1|

◆ cStringToString()

string cStringToString ( const char *  pt)

char* to string

KEY: char* to string, char array to string, char* to string, char pt to string

KEY: char* to string, char array to string, char* to string, char pt to string

◆ det2() [1/2]

template<class T >
T det2 ( vector< T >  v1,
vector< T >  v2 
)

KEY: determinant of two by two matrix A = a b <- v1 c d <- v2

det(A) = ad - bc

vector<vector<float>> v2 = {{1, 2}, {3, 4} }; float n = det2(v2); printf("n=%f\n", n);

◆ det2() [2/2]

template<typename T >
T det2 ( vector< vector< T > >  v2)

KEY: determinant of two by two matrix A = a b c d

det(A) = ad - bc

vector<vector<float>> v2 = {{1, 2}, {3, 4} }; float n = det2(v2); printf("n=%f\n", n);

◆ dotProduct()

template<typename T >
T dotProduct ( vector< T >  v1,
vector< T >  v2 
)

KEY: dot product of two vectors

vector<float> v1 = {1, 2, 3}; vector<float> v2 = {1, 2, 3}; float n = dotProduct(v1, v2); printf("dotProduct=%f\n", n);

◆ geneMatrix()

template<typename T >
vector< vector< T > > geneMatrix ( int  ncol,
int  nrow,
init 
)

Generate ncol x nrow matrix with initial value @init.

◆ head()

template<typename T >
T AronLambda::head ( vector< T >  vec)

head of vector

◆ hexMap()

std::map< char, int > hexMap ( )

0 -> '0' 1 -> '1' 2 -> '2' 3 -> '3' 4 -> '4' 5 -> '5' 6 -> '6' 7 -> '7' 8 -> '8' 9 -> '9' 10 -> 'a' 11 -> 'b' 12 -> 'c' 13 -> 'd' 14 -> 'e' 15 -> 'f'

◆ insertAt()

template<typename T >
vector< T > insertAt ( vector< T >  vec,
int  pos,
vector< T >  insertVec 
)

Insert vector @insertVec into vec at position @pos.

The original vector is NOT modified.

insert([1, 2, 3], 1, [11, 22]) => [1, 11, 22, 2, 3]

@v - original vector

@pos - position that new vector will be inserted at

@insertVec - vector will be inserted at position @pos

Returns
- return new vector contains @vec and @insertVec

◆ intToDouble()

double intToDouble ( int  n)

int to double

◆ isBST()

bool isBST ( Node< int > *  curr,
Node< int > *&  prev 
)

Check whether a Binary Tree is BST.

Java can not be done like that because argument can not be passed by reference in Java.

◆ isEmpty() [1/2]

bool isEmpty ( const char *  cpt)

check if a char* is empty

◆ isEmpty() [2/2]

bool isEmpty ( string  s)

check if a string is empty

◆ last()

template<typename T >
T AronLambda::last ( vector< T >  vec)

last of element in a vector if size() > 0, otherwise error

◆ lcgRandom()

long lcgRandom ( long  x0)

Linear congruential generator.

NOTE: Ubuntu DOES NOT have arc4random_uniform, it works on MacOS only. https://en.wikipedia.org/wiki/Linear_congruential_generator Linear congruential generator

// DO NOT USE arc4random_uniform
arc4random_uniform(n);

◆ maxConsecutiveChar()

int maxConsecutiveChar ( char *  arr,
int  size,
char  c 
)

KEY: find the maximum length of consecutive characters from a string

◆ maxConsecutiveOne()

int maxConsecutiveOne ( vector< int >  vec)

0 0 1 1 1 0 => 3

0 0 1 1 1 0 1 1 1 1 => 4

◆ moveVec()

template<typename T >
vector< T > * moveVec ( a,
vector< T >  vec 
)

use std::move, it acts like Java. Create local object, and return it.

◆ nowMicroseconds()

uint64_t nowMicroseconds ( )
inline

uint64_t t = nowMicroseconds(); cout<<"nowMilliseconds second t="<<t<<endl;

◆ nowMilliseconds()

uint64_t nowMilliseconds ( )
inline

uint64_t t = nowMilliseconds(); cout<<"nowMillionseconds second t="<<t<<endl;

◆ nowNanoseconds()

uint64_t nowNanoseconds ( )
inline

uint64_t t = nowNanoseconds(); cout<<"nowNanoseconds second t="<<t<<endl;

◆ nthRoot()

double nthRoot ( double  c,
int  n,
double  epsilon = 0.000001 
)

Compute the nth root of any positive integer, n >= 1.

TODO: negative number?

◆ operator*() [1/2]

template<typename T >
vector< T > operator* ( a,
vector< T >  vec 
)

scalar multiply vector

  • c * vec

◆ operator*() [2/2]

template<typename T >
vector< T > operator* ( vector< T >  vec,
a 
)

scalar multiply vector

  • vec * c

◆ operator+()

template<typename T >
vector< T > operator+ ( vector< T >  v1,
vector< T >  v2 
)

Concate two vectors, both vectors are NOT modified.

◆ partition()

template<typename T >
T partition ( vector< T > &  vec,
int  lo,
int  hi 
)

partition vector, use [hi] as pivot, like in quicksort

Partition with a tmp vector

◆ partitionInline()

template<typename T >
int partitionInline ( vector< T > &  vec,
int  lo,
int  hi 
)

partition vector inline

Use the inline partition, the space complexity can be O(1), like heap sort.

Partition a vector without a tmp vector

◆ partitionT()

template<typename T >
int partitionT ( array[],
int  lo,
int  hi 
)

partition array inline

partition array with a [hi] = pivot

◆ quickSortT()

template<typename T >
void quickSortT ( array[],
int  lo,
int  hi 
)

KEY: quick sort in an array

◆ random()

int random ( int  n)

random number from 0 to n-1 NOTE: Ubuntu DOES NOT have arc4random_uniform, it works on MacOS only.

arc4random_uniform(n);

◆ randomNanoSec()

vector< int > randomNanoSec ( int  n,
int  max 
)

Simple random number generate based on current nanosecond time

◆ rectangular()

Complex SpaceComplex::rectangular ( std::pair< double, double >  p)

TODO: add test cases

◆ removeAdjacentDuplicateChar()

string removeAdjacentDuplicateChar ( string  s,
char  c 
)

remove adjacent duplicate char from a string

"bbc" b => bc
"bcb" b => abcb

LINE: removeAdjacentDuplicateChar("abb", 'b') => ab

"bbc" b => bc
"bcb" b => abcb

LINE: removeAdjacentDuplicateChar("abb", 'b') => ab

◆ removeIndex() [1/2]

string removeIndex ( string  s,
int  inx 
)

remove char from a string

remove [inx] char from a string removeIndex("cat", 1) => "ct"

◆ removeIndex() [2/2]

template<typename T >
vector< T > removeIndex ( vector< T > &  vec,
int  inx 
)

remove an index from a vector

◆ removeIndexRange()

template<typename T >
vector< T > removeIndexRange ( vector< T > &  vec,
int  fromInx,
int  toInx 
)

remove index from to index inclusively.

  • from index from hight index to low index, otherwise there is error.
for(int i=toInx; i >= fromInx; i--){
ret.erase(ret.begin() + i);
}

◆ repeat()

string repeat ( int  n,
string  s 
)

Repeating n copy of s. The function is inspired by Haskell repeat.

◆ replaceVec()

template<typename T >
vector< T > replaceVec ( oldVal,
newVal,
vector< T >  vec 
)

replace oldVale with newVal in a cloned vector

vec is NOT modified

◆ reverseVec()

template<typename T >
vector< T > reverseVec ( vector< T >  vec)

KEY: reverse vector

vector<T> v(vec); std::reverse(v.begin(), v.end());

◆ splitAt()

template<typename T >
std::pair< vector< T >, vector< T > > splitAt ( int  n,
vector< T >  vec 
)

split vector to pair of vector

vector<int> vec = {1, 2, 3, 4}; splitAt(2, vec) => left side is 2 elements

splitAt(n, vec) => take(2, vec), drop(2, vec)

first = {1, 2} second = {2, 3, 4}

◆ splitStr()

vector< string > splitStr ( string  s,
string  delim 
)

Split string with delimiter.

@s - input string @delim - delimiter

Returns
- vector contains all the strings
vector<string> vec = splitStr("a b c ", " ");
=> [a][b][c][]
vector< string > splitStr(string s, string delim)
Split string with delimiter.
Definition: AronLib.h:1619

◆ splitStrRegex()

vector< std::string > splitStrRegex ( const string &  s,
string  rgxStr = "\\s+" 
)

Split string with regex.

@s - input string

@rgxStr - string passed into regex

Returns
- vector contains all the strings

https://stackoverflow.com/questions/16749069/c-split-string-by-regex

The -1 is the key here: when the iterator is constructed the iterator points at the text that precedes that match and after each increment the iterator points at the text that followed the previous match.

◆ squareRoot()

double squareRoot ( double  a)

Newton' method to find the square root of any positive float point number.

◆ stringToCString()

const char * stringToCString ( string  s)

Convert std::string to char*, same as s2c(string s)

KEY: string to char*

◆ subtract()

template<typename T >
vector< T > subtract ( vector< T >  v1,
vector< T >  v2 
)

subtract two vectors

◆ sumVec()

vector< int > sumVec ( vector< int >  v1,
vector< int >  v2 
)

sum two int vectors

GLOBAL

vector<int> v1 = {9, 2}; vector<int> v2 = {9, 4, 5}; vector<int> v3 = sumVec(v1, v2);

[9][2] [9][4][5] [1][0][3][7]

◆ toBinary()

vector< int > toBinary ( int  n)

int to binary

◆ toCharPtr()

const char * toCharPtr ( string  s)

it is same as s2c but it is better name.

KEY: string to char*, string to char array

◆ toStr()

template<typename T >
string toStr ( const T &  s)

Convert any type to std::string.

T must be overrided <<

◆ tranmat4()

void tranmat4 ( float  arr[16])

KEY: transpose float arr[16]

float arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };

fl(); printArray2df(4, 4, arr);

tranmat4(arr); fl("tran"); printArray2df(4, 4, arr);

◆ transpose()

template<typename T >
vector< vector< T > > transpose ( vector< vector< T > >  mat)

transpose matrix

{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
}
{
{1, 4, 7},
{2, 5, 8},
{3, 6, 9}
}

\[ \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix} \rightarrow \begin{bmatrix} 1 & 4 & 7 \\ 2 & 5 & 8 \\ 3 & 6 & 9 \end{bmatrix} \]

◆ trim()

string trim ( string  str)

trim both ends

trim(" a b c ") => "a b c"
string trim(string str)
trim both ends
Definition: AronLib.h:1547

◆ writeFileAppendRow()

template<typename T >
void writeFileAppendRow ( string  fname,
std::vector< T >  vec 
)

Write vector to file using space as delimiter.