My Project
|
#include <iostream>
#include <fstream>
#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 <experimental/optional>
#include <boost/filesystem/operations.hpp>
#include <vector>
#include </Users/cat/myfile/bitbucket/cpplib/glm/glm/glm.hpp>
#include <dirent.h>
#include <unistd.h>
#include <limits.h>
#include <regex>
#include <algorithm>
#include <cctype>
#include <locale>
#include <stdexcept>
#include <array>
Go to the source code of this file.
Classes | |
class | StopWatch |
Stop watch. More... | |
class | AronGeometry::Vector< T > |
class | AronGeometry::Point< T > |
class | AronGeometry::Pair< T > |
class | AronGeometry::Vector< T > |
class | AronGeometry::Segment< T > |
class | Utility::two< T, U > |
Try to replace pair with two. More... | |
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 | |
Utility | |
many function can be global actually | |
Complex | |
complex number representation and operation number | |
MatrixVector | |
Two dimensional array represents matrix, column and row vector. | |
SpaceVector4 | |
4 dimensions vector | |
Functions | |
template<typename T > | |
void | pl (T t) |
void | nl () |
template<typename T > | |
void | swap (vector< T > &vec, int i, int j) |
int | random (int n) |
random number from 0 to n-1 More... | |
vector< int > | allPrime (int n) |
const char * | stringToCString (string s) |
Convert std::string to char*, same as s2c(string s) More... | |
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. | |
template<typename T > | |
string | toStr (const T &s) |
Convert any type to std::string. More... | |
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 | toStr2 (T &s) |
template<typename T > | |
string | str2 (T &s) |
string | trimLeft (string str) |
string | trimRight (string str) |
string | trim (string str) |
trim both ends More... | |
string | cStringToString (const char *pt) |
char* to string More... | |
string | c2s (const char *pt) |
string to char* | |
bool | containStrRegex (string s, regex rx) |
check s contains regex pattern More... | |
bool | containStr (string str, string pat) |
check if str contain pat More... | |
vector< string > | splitStr (string s, string delim) |
Split string with delimiter. More... | |
template<typename T > | |
std::pair< vector< T >, vector< T > > | splitAt (int n, vector< T > vec) |
split vector to pair of vector More... | |
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 More... | |
template<typename T > | |
vector< T > | insertAt (vector< T > vec, int pos, vector< T > insertVec) |
Insert vector into vec at position . More... | |
vector< std::string > | splitStrRegex (const string &s, string rgxStr="\+") |
Split string with regex. More... | |
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. More... | |
string | charArrToString (const char *pt) |
string | replicate (int n, string s) |
string | repeat (int n, string s) |
template<typename T > | |
vector< T > | repeatVec (int n, T t) |
int | compareCString (char *s1, char *s2) |
int | compareString (string s1, string s2) |
bool | compareFloat (double a, double b) |
void | print (glm::vec3 v3) |
void | print (glm::vec2 v2) |
void | printLn (glm::vec3 v3) |
void | printLn (glm::vec2 v2) |
string | toString (glm::vec3 v3) |
template<typename T > | |
vector< vector< T > > | transpose (vector< vector< T >> mat) |
transpose matrix More... | |
template<typename T > | |
bool | compareArray (T arr1[], T arr2[], const int s1) |
template<typename T > | |
void | print (std::pair< T, T > pair) |
template<typename T > | |
void | print (vector< T > vec) |
template<typename T > | |
void | print (vector< vector< T > > vec) |
template<typename T > | |
void | print (T t) |
template<typename T > | |
void | printNb (T t) |
print no bracket | |
template<typename T > | |
void | printLn (T t) |
template<typename T > | |
void | printLnNb (T t) |
template<typename T > | |
void | ppL (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) |
template<typename T > | |
vector< T > * | moveVec (T a, vector< T > vec) |
use std::move, it acts like Java. Create local object, and return it. | |
int | unsignToInt (size_t u) |
template<typename T > | |
vector< T > * | append (vector< T > vec, T a) |
use std::move, it acts like Java. Create local object, and return it. More... | |
int | length (string s) |
length of string | |
int | len (string s) |
length of string | |
template<typename T > | |
int | length (vector< T > v) |
length of vector | |
template<typename T > | |
int | len (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 More... | |
template<typename T > | |
vector< T > | operator* (T a, vector< T > vec) |
scalar multiply vector More... | |
template<typename T > | |
vector< T > | operator* (vector< T > vec, T a) |
scalar multiply vector More... | |
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 > | range (int a, int b, int stride=1) |
template<typename T > | |
vector< T > | geneVector (int a, int b) |
template<typename T > | |
vector< vector< T > > | geneMatrix (int ncol, int nrow, T init) |
Generate ncol x nrow matrix with initial value . | |
template<typename T > | |
void | swapT (T array[], int i, int j) |
template<typename T > | |
T | partitionT (T array[], int lo, int hi) |
partition array inline More... | |
template<typename T > | |
T | partition (vector< T > &vec, int lo, int hi) |
partition vector, use [hi] as pivot, like in quicksort | |
template<typename T > | |
T | partititonInline (vector< T > &vec, int lo, int hi) |
partition vector inline More... | |
template<typename T > | |
void | quickSortT (T array[], int lo, int hi) |
void | SpacePrint::pp (const char *format,...) |
void | SpacePrint::fl () |
void | SpacePrint::fw (string s) |
template<typename T > | |
void | SpacePrint::pp (T t) |
template<typename T > | |
void | SpacePrint::pp (T t1, T t2) |
template<typename T > | |
void | SpacePrint::pp (T t1, T t2, T t3) |
template<typename T , typename U > | |
void | SpacePrint::pp (std::pair< T, U > p) |
void | SpacePrint::pp (int n) |
void | SpacePrint::pp (float n) |
void | SpacePrint::pp (long n) |
void | SpacePrint::pp (unsigned long n) |
void | SpacePrint::fl (string s) |
template<typename T > | |
void | swap (T arr[], int i, int j) |
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) |
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 | writeFileAppendVector (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. | |
bool | Utility::isSubstring (string sub, string s) |
Check whether sub is the substring of s. More... | |
int | Utility::substringFirstIndex (string sub, string s) |
find the index of sub in string s More... | |
int | Utility::strToInt (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. More... | |
template<typename T > | |
T ** | MatrixVector::allocate (int ncol, int nrow) |
Allocate a matrix: height = ncol, width = nrow. More... | |
template<typename T > | |
T ** | MatrixVector::vecVecToArrArr (vector< vector< T > > vv) |
Convert Vector< Vector<T> > to dynamic T**. More... | |
template<typename T > | |
vector< vector< T > > | MatrixVector::arrArrToVecVec (T **arr, int ncol, int nrow) |
Convert T** arr to vector<vector<T>> v2. More... | |
mat | MatrixVector::concat (mat m1, mat m2) |
mat | MatrixVector::identity (int n) |
vec | MatrixVector::backwardSubstitute (mat a, vec b) |
Backward Substitute. More... | |
mat | MatrixVector::ltri (mat m, int index) |
Get the L triangle from a matrix \[ \begin{equation} \begin{aligned} &v_k = \begin{bmatrix} 0 \\ \vdots \\ 0 \\ l_{k+1,k} \\ l_{k+2,k} \\ \vdots \\ l_{m,k} \\ \end{bmatrix} \\ &v_k e_{k}^{*} = \begin{bmatrix} 0 & & & & \\ & \ddots & & & \\ & & 0 & & \\ & & l_{k+1,k} & & \\ & & \vdots & \ddots & \\ & & l_{m,k} & & 0 \\ \end{bmatrix} \\ \end{aligned} \end{equation} \] | |
std::pair< mat, mat > | MatrixVector::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 | writeFile (string fname, mat &m) |
vector<T>* append | ( | vector< T > | vec, |
T | a | ||
) |
use std::move, it acts like Java. Create local object, and return it.
Better name
bool binSearch | ( | T | key, |
T | arr[], | ||
int | lo, | ||
int | hi | ||
) |
binary search on a sorted array
k = 4 1 1 2 2 4 x 2 4 x 4 t
int compareCString | ( | char * | s1, |
char * | s2 | ||
) |
compare char* char* return n < 0, n == 0, n > 0
bool compareFloat | ( | double | a, |
double | b | ||
) |
compare float float
int compareString | ( | string | s1, |
string | s2 | ||
) |
compare string string return n < 0, n == 0, n > 0
bool containStr | ( | string | str, |
string | pat | ||
) |
check if str contain pat
bool containStrRegex | ( | string | s, |
regex | rx | ||
) |
check s contains regex pattern
string cStringToString | ( | const char * | pt | ) |
char* to string
KEY: char* to string, char array to string, char* to string
vector<T> insertAt | ( | vector< T > | vec, |
int | pos, | ||
vector< T > | insertVec | ||
) |
Insert vector into vec at position .
The original vector is NOT modified.
insert([1, 2, 3], 1, [11, 22]) => [1, 11, 22, 2, 3]
- original vector
- position that new vector will be inserted at
- vector will be inserted at position
double intToDouble | ( | int | n | ) |
int to double
bool isEmpty | ( | string | s | ) |
check if a string is empty
bool isEmpty | ( | const char * | cpt | ) |
check if a char* is empty
double nthRoot | ( | double | c, |
int | n, | ||
double | epsilon = 0.000001 |
||
) |
Compute the nth root of any positive integer, n >= 1.
TODO: negative number?
vector<T> operator* | ( | T | a, |
vector< T > | vec | ||
) |
scalar multiply vector
vector<T> operator* | ( | vector< T > | vec, |
T | a | ||
) |
scalar multiply vector
T partitionT | ( | T | array[], |
int | lo, | ||
int | hi | ||
) |
partition array inline
partition array with a [hi] = pivot
T partititonInline | ( | vector< T > & | vec, |
int | lo, | ||
int | hi | ||
) |
partition vector inline
Use the inline partition, the space complexity can be O(1), like heap sort.
int random | ( | int | n | ) |
random number from 0 to n-1
Complex SpaceComplex::rectangular | ( | std::pair< double, double > | p | ) |
TODO: add test cases
vector<T> replaceVec | ( | T | oldVal, |
T | newVal, | ||
vector< T > | vec | ||
) |
replace oldVale with newVal in a cloned vector
vec is NOT modified
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}
vector<string> splitStr | ( | string | s, |
string | delim | ||
) |
Split string with delimiter.
- input string - delimiter
vector<std::string> splitStrRegex | ( | const string & | s, |
string | rgxStr = "\\s+" |
||
) |
Split string with regex.
- input string
- string passed into regex
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.
double squareRoot | ( | double | a | ) |
Newton' method to find the square root of any positive float point number.
const char* stringToCString | ( | string | s | ) |
Convert std::string to char*, same as s2c(string s)
KEY: string to char*
string toStr | ( | const T & | s | ) |
Convert any type to std::string.
T must be overrided <<
vector<vector<T> > transpose | ( | vector< vector< T >> | mat | ) |
transpose matrix
\[ \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} \]
string trim | ( | string | str | ) |
trim both ends