Example #1
0
func ObjectIDOfWebString(s string) bson.ObjectId {
	b, err := hex.DecodeString(s)
	if err != nil {
		return ""
	}
	return bson.ObjectId(b)
}
Example #2
0
func (kp *KPartite) makeEdgeID(from, to bson.ObjectId) bson.ObjectId {
	kp.Lock()
	kp.edgeHash.Reset()
	kp.edgeHash.Write([]byte(from))
	kp.edgeHash.Write([]byte(to))
	h := kp.edgeHash.Sum()
	kp.Unlock()
	return bson.ObjectId(h[:IDLEN])
}
Example #3
0
func chooseID() bson.ObjectId {
	rand.Seed(time.Nanoseconds())
	b := make([]byte, IDLEN)
	for i := 0; i < IDLEN/4; i++ {
		u := rand.Uint32()
		b[4*i] = byte(u & 0xff)
		b[4*i+1] = byte((u >> 8) & 0xff)
		b[4*i+2] = byte((u >> 16) & 0xff)
		b[4*i+3] = byte((u >> 24) & 0xff)
	}
	return bson.ObjectId(b)
}