Esempio n. 1
0
func LoadEdge(g *goiso.Graph, vids types.Map, data []byte) (err error) {
	obj, err := ParseJson(data)
	if err != nil {
		return err
	}
	_src, err := obj["src"].(json.Number).Int64()
	if err != nil {
		return err
	}
	_targ, err := obj["targ"].(json.Number).Int64()
	if err != nil {
		return err
	}
	src := int(_src)
	targ := int(_targ)
	label := strings.TrimSpace(obj["label"].(string))
	if o, err := vids.Get(types.Int(src)); err != nil {
		return err
	} else {
		u := o.(*goiso.Vertex)
		if o, err := vids.Get(types.Int(targ)); err != nil {
			return err
		} else {
			v := o.(*goiso.Vertex)
			g.AddEdge(u, v, label)
		}
	}
	return nil
}
Esempio n. 2
0
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
}