func tarjanSort(successors map[bson.ObjectId][]bson.ObjectId) [][]bson.ObjectId { // http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm data := &tarjanData{ successors: successors, nodes: make([]tarjanNode, 0, len(successors)), index: make(map[bson.ObjectId]int, len(successors)), } // Sort all nodes to stabilize the logic. var all []string for id := range successors { all = append(all, string(id)) } sort.Strings(all) for _, strid := range all { id := bson.ObjectId(strid) if _, seen := data.index[id]; !seen { data.strongConnect(id) } } return data.output }
func bid(n int) bson.ObjectId { return bson.ObjectId(fmt.Sprintf("%024d", n)) }
// MarshalJSON turns a dal.ObjectId into a json.Marshaller. func (id ObjectID) MarshalJSON() ([]byte, error) { return bson.ObjectId(id).MarshalJSON() }
func (id ObjectID) Valid() bool { return bson.ObjectId(id).Valid() }
func (id ObjectID) Hex() string { return bson.ObjectId(id).Hex() }
func (id ObjectID) GetBSON() (interface{}, error) { return bson.ObjectId(id), nil }