func outOfOrder(l *list.List) { iTotal := 25 if iTotal > l.Len() { iTotal = l.Len() } ll := make([]*list.List, iTotal) for i := 0; i < iTotal; i++ { ll[i] = list.New() } r := rand.New(rand.NewSource(time.Now().UnixNano())) for e := l.Front(); e != nil; e = e.Next() { fpath, ok := e.Value.(string) if !ok { panic("The path is invalid string") } if rand.Int()%2 == 0 { ll[r.Intn(iTotal)].PushFront(fpath) } else { ll[r.Intn(iTotal)].PushBack(fpath) } } r0 := rand.New(rand.NewSource(time.Now().UnixNano())) l.Init() for i := 0; i < iTotal; i++ { if r0.Intn(2) == 0 { l.PushBackList(ll[i]) } else { l.PushFrontList(ll[i]) } ll[i].Init() } }
// GetAllItems fill the list itemList with all items in the tree. func (this *quadTreeNode) GetAllItems(itemList *list.List) { itemList.PushBackList(this.items) if this.isPartitioned { this.topLeftNode.GetAllItems(itemList) this.topRightNode.GetAllItems(itemList) this.bottomLeftNode.GetAllItems(itemList) this.bottomRightNode.GetAllItems(itemList) } }
// Fill itemList with all items that could collide with the given Rect. func (this *quadTreeNode) GetItems(itemList *list.List, rect *Rect) { var node *quadTreeNode = nil var err bool = false if this.isPartitioned { node, err = this.GetNode(rect) if !err { node.GetItems(itemList, rect) } else if err { this.GetAllItems(itemList) } } itemList.PushBackList(this.items) }
func FindChildren(n *html.Node, predicate func(*html.Node) bool) list.List { results := list.List{} if predicate(n) { results.PushBack(n) } for c := n.FirstChild; c != nil; c = c.NextSibling { inner_results := FindChildren(c, predicate) if inner_results.Len() > 0 { results.PushBackList(&inner_results) } } return results }