I happen to see this clip where he explains why vector is better than linked list.
How about in Go? I was coding some graph algorithms that do a lot of insertion and deletion in a list of nodes. First I implemented it with slice, but later switched it to container/list because I wanted the following method:
// Delete a Vertex from the graph.
func (G *Graph) DeleteVertex(A *Vertex) {
for vtx := G.VertexList.Front(); vtx != nil; vtx = vtx.Next() {
if vtx.Value.(*Vertex) == A {
// remove from the graph
G.VertexList.Remove(vtx)
}
}
// traverse all the outgoing edge(vertex)
// remove this vertex A from the predecessor of the vertices,
// also delete the edges from A
for edge := A.GetEdgeListFromThisVertex().Front(); edge != nil; edge = edge.Next() {
G.DeleteEdgeFrom(A, edge.Value.(*Edge).DestinationVertex)
for vtx := edge.Value.(*Edge).DestinationVertex.Predecessor.Front(); vtx != nil; vtx = vtx.Next() {
edge.Value.(*Edge).DestinationVertex.Predecessor.Remove(vtx)
}
}
}
Then why and when should I use container/list? Now I get used to it, but sometimes dealing with type interface {} feels tedious.