原创 關於函數作爲參數傳遞給函數

javascript中,函數可以作爲參數傳遞給另一個函數。這是因爲js中的函數名實際上是一個變量,而變量是可以作爲參數進行傳遞的,當然也可以作爲返回值進行返回。 <html> <body> <script> function ad

原创 leetcode-50-pow

實現pow(double x, int n): double 最直接的方法:挨個乘起來。時間複雜度O(n)。該種做法耗時且浪費了可重複利用的資源。根據二分查找的思想,將累乘對半、對半、再對半劃分,只需算一半便可得出結果,如下圖所示

原创 可以用作棧和隊列的模型

整數可以用作簡單的棧來使用,整數0,入棧加1,出棧減1。這種方式只能用作使用棧進行簡單判斷的地方,不適用於使用棧來存放數據。 比如判斷括號是否匹配正確,(()()),這樣的就是正確的,())( )),這樣的就是不正確的,且只能

原创 endianconv.h

/* variants of the function doing the actual conversion only if the target * host is big endian */ #if (BYTE_ORDER

原创 tcmalloc簡單介紹

github 地址 thread-caching malloc 與標準庫glibc的malloc相比,tcmalloc的分配速度和效率都要高,在併發情況下性能上有提升。 實現原理的簡單介紹: (1)每個線程分配一個單獨的cache

原创 ziplist

版本6.0.1 ziplist.c 初始化ziplist /* Create a new empty ziplist. */ unsigned char *ziplistNew(void) { unsigned int b

原创 atomicvar.h

版本6.0.1 定義原子操作 使用pthread庫定義如下 /* Implementation using pthread mutex. */ #define atomicIncr(var,count) do { \ p

原创 gc過程

runtime 文檔描述 // 1. GC performs sweep termination. // // a. Stop the world. This causes all Ps to reach a GC safe

原创 synchronized and wait

下面是zookeeper中的一個應用 private AddressTuple getAddrs() { AddressTuple addrs = myAddrs.get(); if (addrs

原创 sync.Cond

go version go1.13.4 linux/amd64 用於同步多個協程間的條件狀態 比如在消費者-生產者模型中,只有在隊列中有資源時,消費者纔可以消費,只有在隊列還能夠放入資源時,生產者纔可以放入資源。消費者協程和生產者

原创 QuorumPeer.setQuorumVerifier

public QuorumVerifier setQuorumVerifier(QuorumVerifier qv, boolean writeToDisk) { synchronized (QV_LOCK) {

原创 配置文件解析

簡單的zoo.cfg配置如下 tickTime=2000 dataDir=/var/lib/zookeeper clientPort=2181 initLimit=5 syncLimit=2 server.1=zoo1:2888:

原创 zookeeper源碼分析

版本 zookeeper-release-3.6.1 啓動類 ~/zk/zookeeper-release-3.6.1/zookeeper-server/src/main/java/org/apache/zookeeper/ser

原创 Linux

在終端進入root 在終端輸入sudo -s,然後輸入當前用戶的密碼,注意這時輸入的密碼不會顯示在終端。注意所有輸入的密碼都不會顯示在終端,而且也不會出現點或者星號。 創建新用戶 首先進入root,然後使用adduser

原创 leetcode-10-正則表達式

abc      .*abc 考慮這種情況,是匹配的。即帶*號的可以理解是爲備用情況,只有當不使用.*時後面無法匹配才使用.*,比如這種情況abc      .*bc。 public boolean isMatch(Stri