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
再谈到聚簇索引,它的叶子页内存放的是实际的行纪录。不像普通索引,叶子页内存放的只有索引的值和聚簇索引的值,最终的查询,还须要归根到查询聚簇索引上。对象