Public speaking course notes Read "Dynamo, Amazon’s Highly Available Key-value Store" Read "Bigtable, A Distributed Storage System for Structured Data" Read "Streaming Systems" 3, Watermarks Read "Streaming Systems" 1&2, Streaming 101 Read "F1, a distributed SQL database that scales" Read "Zanzibar, Google’s Consistent, Global Authorization System" Read "Spanner, Google's Globally-Distributed Database" Read "Designing Data-intensive applications" 12, The Future of Data Systems IOS development with Swift Read "Designing Data-intensive applications" 10&11, Batch and Stream Processing Read "Designing Data-intensive applications" 9, Consistency and Consensus Read "Designing Data-intensive applications" 8, Distributed System Troubles Read "Designing Data-intensive applications" 7, Transactions Read "Designing Data-intensive applications" 6, Partitioning Read "Designing Data-intensive applications" 5, Replication Read "Designing Data-intensive applications" 3&4, Storage, Retrieval, Encoding Read "Designing Data-intensive applications" 1&2, Foundation of Data Systems Three cases of binary search TAMU Operating System 2 Memory Management TAMU Operating System 1 Introduction Overview in cloud computing 2 TAMU Operating System 7 Virtualization TAMU Operating System 6 File System TAMU Operating System 5 I/O and Disk Management TAMU Operating System 4 Synchronization TAMU Operating System 3 Concurrency and Threading TAMU Computer Networks 5 Data Link Layer TAMU Computer Networks 4 Network Layer TAMU Computer Networks 3 Transport Layer TAMU Computer Networks 2 Application Layer TAMU Computer Networks 1 Introduction Overview in distributed systems and cloud computing 1 A well-optimized Union-Find implementation, in Java A heap implementation supporting deletion TAMU Advanced Algorithms 3, Maximum Bandwidth Path (Dijkstra, MST, Linear) TAMU Advanced Algorithms 2, B+ tree and Segment Intersection TAMU Advanced Algorithms 1, BST, 2-3 Tree and Heap TAMU AI, Searching problems Factorization Machine and Field-aware Factorization Machine for CTR prediction TAMU Neural Network 10 Information-Theoretic Models TAMU Neural Network 9 Principal Component Analysis TAMU Neural Network 8 Neurodynamics TAMU Neural Network 7 Self-Organizing Maps TAMU Neural Network 6 Deep Learning Overview TAMU Neural Network 5 Radial-Basis Function Networks TAMU Neural Network 4 Multi-Layer Perceptrons TAMU Neural Network 3 Single-Layer Perceptrons Princeton Algorithms P1W6 Hash Tables & Symbol Table Applications Stanford ML 11 Application Example Photo OCR Stanford ML 10 Large Scale Machine Learning Stanford ML 9 Anomaly Detection and Recommender Systems Stanford ML 8 Clustering & Principal Component Analysis Princeton Algorithms P1W5 Balanced Search Trees TAMU Neural Network 2 Learning Processes TAMU Neural Network 1 Introduction Stanford ML 7 Support Vector Machine Stanford ML 6 Evaluate Algorithms Princeton Algorithms P1W4 Priority Queues and Symbol Tables Stanford ML 5 Neural Networks Learning Princeton Algorithms P1W3 Mergesort and Quicksort Stanford ML 4 Neural Networks Basics Princeton Algorithms P1W2 Stack and Queue, Basic Sorts Stanford ML 3 Classification Problems Stanford ML 2 Multivariate Regression and Normal Equation Princeton Algorithms P1W1 Union and Find Stanford ML 1 Introduction and Parameter Learning

C basics

2017-04-04

data type

integer

// 32 bit or 4 Bytes
int Max = 0;
// short int 16 bit or long 32 bit
short a;
long b;
// size of type
cout << sizeof(short int)<<endl;
// character
char ch = "A";

Convert every 4 digits for hex, 3 for oct.

cout << hex << a << endl;
// dec for 10-  
//input hex number, starting with 0x; use 0 for oct
int a = 0xFFF85;

max and min value

// 4.2 billion
unsigned int a= 0xFFFFFFFF;
cout << dec << a << endl;
// 2.1 billion
signed int a= 0x7FFFFFFF;
cout << dec << a << endl;

float

  • float, 32 bit, 7-digit precision
  • double, 64 bit, 15-digit precision
  • long double, 64 bit, 15-digit precision

cout will print 6-digit.

// set precision
cout << setprecision(100) << a << endl;
// input  
float a = 0;
a = 1234.56e5;

Avoid add a large number with a small number.

Character

char a = 64;
int b = 'z';
//
cout << '\a' << '\\' << '\n';

Boolean

//True, non-zero
bool b1 = true;
b1 = -100;
b1 = 7 > 3;
//False, zero

constant

const double PI = 3.14;
n = 10000L; // long int const
x = 3.14L;
y = 3.14F;
k = 1000U; // unsigned

variable name

input & output

// to use setprecision()
#include<iomanip>
cout << fixed << setprecision(2) << f;

operator

  • sizeof
  • subscript []
  • logic: ! && ||
  • digit >> ~ | ^ &

assign value =

  1. different type, auto-conversion
  2. long to short, trim the low digit to short
  3. short to long, keep the same
  4. sign bit, assign value no matter sign or digit bit
a += 3
x *= y+8
x %= 3
a = b = c = 5;

arithemic

++i; i++

comma, if, conversion

// calculate 1 then 2 ...,  value of last
a = 3*5, a*4; // last value is 60
max = (a>b) ? a:b;
(double)a // convert value of a and pass, a doesn't change

bit operation

  • and : &, do and independently for every bit
  • or : |
  • xor : ^
  • not : ~
  • left move : a<<2, move every bit to left by a bit, discard overflow high bit, give 0 to new low bit. like *2 while move 1 bit if nothing discarded
  • right move : >>

exchange two values

a = a^b;
b = b^a;
a = a^b;

control flow

// switch
switch (expression) {
    default: expr0;
    case value: expr1;
    case ...
}

// for 
for (int i = 0; i < 10; i++) {
    break;
    continue;
    
}

// while
while ( expr) {

}

// do while
do
{

} while (expr);

array

definition

float sheep[10];

// must use constant for size of array
const int i = 4;
int a[i];
    // or
#define N 4
int main() {
    int a[N];
}
// subscript starts from 0

// pre-allocation
int a[ ] = {1,2,3};
    // other value will be 0
int a[4] = {1,2};
int a[4] = {0};

2-D array

int a[3][4] = { {1,2,3,4},{5,6,7,8},{9,10,11,12}};
int a[ ][4] = {1,2,3,4,5,6,7,8}; // 2 rows, 4 columns
int a[ ][4] = { {1},{0,6},{0,0,1} }; // fill with zeros

3-D array

int a[3][4][5];

using variable as array size

#include<vector>

vector<int> a(length,value);

string array

// other value will be initialized as '\0\'
char a[10] = {'a','b','c'};

char c[] = {'a','b','c'};

// double quote, has one extra value '\0'
char c[] = "China"
char c[5] = "China"; // invalid
// cannot assign value like this
str1[] = "China";
str1 = "China";
str2 = str1;
// use function to assign values
char str1[] = "C++ lang", str2[20];
int i = 0;
while (str1[i] != '\0') {
    str2[i] = str1[i];
    i++;
}
str2[i] = '\0';

2-D array

char weekday[7][11] = {"Sunday",...};

cin

// space and return will be treated as separator
while (cin >> grade) {
}
// but following will receive space and return
while ((c=cin.get()) != EOF) {
}
// equivalent to
while (cin.get(c)) 
// don't skip any char
while (c = getchar())

a sequence of chars

char a[10] = "Computer";
cout <<a; \\ end with '\0'

// 2d
char weekday[7][11] = {...};
for (int i = 0, i < 7; i++) 
    cout << weekday[i]<<endl;
    

cin

char str[10];
cout << "enter a sentence:" << endl;
while (cin >> str)
    cout <<str << endl;
    
\\ cin.get(variable_name, number to read, stop sign)
\\ return 1 if success, 0 while stopped
\\ if 'o' is stop sign
(cin.get(ch,10,'\n'); \\ pointer stopped at exactly before stop sign 'we are g~ood'
cin.getline(ch,10,'\n'); \\ pointer stopped at one pos after stop sign, 'we are go~od`

\\
cin >> n;
cin.get() \\ read extra return

\\ 
while (cin.getline(str,200))
{

}

assign value

#include<string>

strcpy(str2,str1);

Creative Commons License
Melon blog is created by melonskin. This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
© 2016-2024. All rights reserved by melonskin. Powered by Jekyll.