close

同樣是看code學習,把同班同學好的code拿出來看,不懂的筆記在這裡

 

1. 如何有效率free vector memory

因為用clear() 本身只是把element 清掉,但是空間並不會減少,有人主張用resize,不過更好的是用 temporary vector swap 

vector<string> vec(1000);

…

vec.clear();
vector<string>().swap(vet);

 

2.複習一下好的命名方式    (匈牙利命名法因為會透露資料的type,涉及資安問題,建議是不要用)

函數單字字首字母大寫               ex. MyExcitingFunction()

class,struct 單字首字母大寫      

變數命名一率小寫

常數命名前+k                        

ex.

struct UrlTableProperties {
    string name;
    int num_entries;
 const int kDaysInAWeek = 7;
}

3. 看到有同學用suffix automaton 不過還沒研究完他怎麼實作的,先memo下來 

應該會比我用hashtable更好,然後也要把Aho-Corasick Algorithm, KMP 瞭解一下

 

4. struct 的define 可同時命變數

struct Buf {double O, C, D; char idx; } buf[6];

 後面的 buf[6]  就是變數

 

arrow
arrow
    全站熱搜

    angledark0123 發表在 痞客邦 留言(0) 人氣()