Пример #1
0
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
}
Пример #2
0
func bid(n int) bson.ObjectId {
	return bson.ObjectId(fmt.Sprintf("%024d", n))
}
Пример #3
0
// MarshalJSON turns a dal.ObjectId into a json.Marshaller.
func (id ObjectID) MarshalJSON() ([]byte, error) {
	return bson.ObjectId(id).MarshalJSON()
}
Пример #4
0
func (id ObjectID) Valid() bool {
	return bson.ObjectId(id).Valid()
}
Пример #5
0
func (id ObjectID) Hex() string {
	return bson.ObjectId(id).Hex()
}
Пример #6
0
func (id ObjectID) GetBSON() (interface{}, error) {
	return bson.ObjectId(id), nil
}