go
語言的排序經過接口來實現,接口的聲明以下:html
type Interface interface { // Len is the number of elements in the collection. Len() int // Less reports whether the element with // index i should sort before the element with index j. Less(i, j int) bool // Swap swaps the elements with indexes i and j. Swap(i, j int) }
其實核心仍是Less
方法,只要選擇一個比較對象,看看須要正序仍是倒序就能夠。好比,按照正序來排列:app
func ( l HotList) Less(i, j) bool { return l[i] < l[j] }
MySQL
中InnoDB
索引是如何實現查找的呢?索引實際上是B+
樹,balance
的意思。全部的葉子節點是一個有續集,特地去 Copy 了一張圖:code
經過B+
樹查找以後,咱們最終會找到一個葉子頁。通常來講,每一個葉子頁應該至少保證有兩條記錄。要獲得具體的數據,咱們還須要在這個Page
內查找。htm
再談到聚簇索引,它的葉子頁內存放的是實際的行紀錄。不像普通索引,葉子頁內存放的只有索引的值和聚簇索引的值,最終的查詢,還須要歸根到查詢聚簇索引上。對象