示例#1
0
文件: graph.go 项目: timtadh/graple
func LoadVertex(g *goiso.Graph, supportAttr string, vids types.Map, nodeAttrs *bptree.BpTree, supportAttrs map[int]string, data []byte) (err error) {
	obj, err := ParseJson(data)
	if err != nil {
		return err
	}
	_id, err := obj["id"].(json.Number).Int64()
	if err != nil {
		return err
	}
	label := strings.TrimSpace(obj["label"].(string))
	id := int(_id)
	vertex := g.AddVertex(id, label)
	err = vids.Put(types.Int(id), vertex)
	if err != nil {
		return err
	}
	if nodeAttrs != nil {
		bid := make([]byte, 4)
		binary.BigEndian.PutUint32(bid, uint32(vertex.Idx))
		err = nodeAttrs.Add(bid, data)
		if err != nil {
			return err
		}
		if supportAttr != "" {
			if _, has := obj[supportAttr]; !has {
				return fmt.Errorf("vertex did not have required supportAttr %v\n%v", supportAttr, string(data))
			}
			supportAttrs[vertex.Idx] = obj[supportAttr].(string)
		}
	}
	return nil
}
示例#2
0
文件: maximal.go 项目: timtadh/graple
func addToLabels(labels *bptree.BpTree, label []byte) {
	has, err := labels.Has(label)
	if err != nil {
		log.Println(err)
	}
	if !has {
		err = labels.Add(label, []byte{0})
		if err != nil {
			log.Println(err)
		}
	}
}