Posts

Install google-glog 0.6.0 on Ubuntu 22.04

Download and compile and install goolge glog $ git clone https://github.com/google/glog.git  $ sudo apt install autoconf automake libtool $ cd glog $ cmake -S . -B build -G "Unix Makefiles" $ cmake --build build $ cd build $ make $ sudo make install $ sudo ldconfig Test #include <iostream> #include <glog/logging.h> int main(int argc, char **argv) { google::SetLogDestination(google::INFO, "/home/jimmy/glog.log"); google::InitGoogleLogging("log_test"); LOG(INFO) << "This is INFO!"; LOG(WARNING) << "This is WARNING!"; LOG(ERROR) << "This is ERROR!"; LOG(FATAL) << "This is FATAL"; return 0; } Compile command is as following: $ g++ glog_test.cc -lglog

Fullscreen for FreeBSD VMWare

There is the solution: # pkg install open-vm-tools # pkg install xf86-video-vmware

Install samba on FreeBSD(on VMware Workstation) to share files with Window.

1 Search and Install Samba # pkg search samba # pkg install samba413 2 Adding user on FreeBSD # adduser Username: samba1 3 Samba Configuration Creating a directory to  share or note an existing directory that you would like shared. Change "samba1" to your user. # mkdir /smbshare # chown samba1 /smbshare # vim /usr/local/etc/smb4.conf Adding the text to the file smb4.conf (again, change "samba1" to your user). [global] workgroup = WORKGROUP server string = Samba Server Version %v netbios name = ExampleMachine wins support = Yes security = user passdb backend = tdbsam # Example: share /smbshare accessible only to "samba1" user [src] path = /smbshare valid users = samba1 writable = yes browsable = yes read only = no guest ok = no public = no create mask = 0666 directory mask = 0755 4 Add user to samba We need to create a specific samba user. This can be the same user as your system user, but still must be done to allow samba to have its own user. Note th

Quicksort

Quicksort, like merge sort, applies the divid-and-conquer paradigm. Here is the three-step divide-and-conquer process for sorting a typical subarray A[p..r]: Divide: Partition (rearrange) the array A[p..r] into two (possibly empty) subarrays A[p..q-1] and A[p+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, in turn, less than or equal to each element of A[p+1..r]. Compute the index q as part of this partitioning procedure. Conquer: Sort the two subarrays A[p..q-1] and A[q+1..r] by recursive calls to quicksort. Combine: Because the subarrays are already sorted, no work is needed to combine them: the entire array A[p..r] is now sorted. The following procedure implements quicksort: QUICKSORT(A, p, r) if p < r q = PARTITION(A, p, r) QUICKSORT(A, p, q - 1) QUICKSORT(A, q + 1, r) To sort an entire array A, the initial call is QUICKSORT(A, 1, A.length). Partitioning the array The key to the algorithm is the PARTITION procedure,

RTOS

A real-time operation system ( RTOS ) is an operation system for real-time application that processes data and events  that have critically defined time constraints. The mainstream RTOS as following: μC/OS-III ( Micro-Controller Operation Systems ) FreeRTOS RT-Thread Alios-Thread RTX

CLRS Solutions 6.3 Building a heap

Image
6.3-2 Why do we want the loop index $i$ in line 2 of BUILD-MAX-HEAP to decrease from $\lfloor A.length/2 \rfloor$ to 1 rather than increase from to $\lfloor A.length/2 \rfloor$? Otherwise we won't be allowed to call MAX-HEAPIFY, since it will fail the condition of having the subtrees be max-heaps. That is, if we start with 1, there is no guarantee that A[2] and A[3] are roots of max-heaps. 6.3-3 Show that there are at most $\lceil n/2^{h+1}\rceil$ nodes of height $h$ in any $n$-element heap. The height of binary heap is as following: A heap of size $n$ has at most $\lceil n/2^{h+1} \rceil$ nodes with height $h$. Key Observation : For any $n > 0$, the number of leaves of nearly complete binary tree is $\lceil n/2 \rceil$. Proof by induction Base case : Show that it's true for $h = 0$. This is the direct result from above observation. Inductive step : Suppose it's ture for $h - 1$. Let $N_h$ be the number of nodes at height $h$ in the n-node tree $T$. Consider the tre

CLRS Solutions 6.2 Maintaining the heap property

 6.2-2 Staring with the procedure MAX-HEAPIFY, write pseudocode for the procedure MIN-HEAPIFY(A, i), which performs the corresponding manipulation on a min-heap. How does the running time of MIN-HEAPIFY compare to that of MAX-HEAPIFY? MIN-HEAPIFY(A, i) l = LEFT(i) r = RIGHT(i) if l ≤ A.heap-size and A[l] < A[i] smallest = l else smallest = i if r ≤ A.heap-size and A[r] < A[smallest] smallest = r if smallest != i exchange A[i] with A[smallest] MIN-HEAPIFY(A, smallest) The running time is the same. Actually, the algorithm is the same with the exceptions of two comparisons and some names. 6.2-5 The code for MAX-HEAPIFY is quite efficient in terms of constant factors, except possibly for the recursive call in line 10, which might cause some compilers to produce inefficient code. Write an efficient MAX-HEAPIFY that uses an interative control construct (a loop) instead of recursion. MAX-HEAPIFY(A, i) while true l = LEFT(i) r = RIGHT(i)