0

here is the code and i use gccgo for compilation. this for a graph based organizer. I don't need advise on graph algorithms.

package element

import (
        "fmt"
        "strings"
        "io"
        "strconv"
)

type Node struct {
    id   int
    name string
    props map[string]string
    links map[string][]*Node
}

var names = make(map[string]int , 8)
var nodes = make(map[string][]*Node , 8)


//========functions================
func new_node(Id int) *Node {
    return  &Node( Id, " ", nil, nil) 
}

func getNode_byId(nodes []*Node, id int) *Node {    
    for _, node := range nodes{
        if node.id == id {
            return node
        }
    }
    return nil
}

func addNode(store string, node *Node) {
    nodes[store] = append(nodes[store], node)
}

func addLinkToNode(node, link *Node, property string) {
    node.links[property] = append(node.links[property], link)
}

func nodeFromString(str string, typ string) {

    lines := strings.Split(str, "\n")
    lcount := len(lines)

    if lines[0] == "[begin]" && lines[lcount] == "[end]" {
        fmt.Println("common dude! something wrong with ur string")
        return
    }

    fields  := strings.Fields(lines[1])
    id , _  := strconv.Atoi(fields[1])
    nod     := getNode_byId(nodes[typ], id )

    if nod == nil { nod = new_node(id) }
    addNode(typ, nod)

    nod.name = typ

    lines = lines[2:]
    ind :=0
    for index, line := range lines {
        fields := strings.Fields(line)
        if field := fields[0]; field[0] != '-' {
            ind = index
            break
        }

        nod.props[fields[0]] = fields[1]
    }

    lines = lines[ind:] 
    for index, line := range lines {
        if line[0]!= '+' {
            ind = index
            break
        }

        pivot := strings.Index(line, " ")
        field := line[0:pivot]
        fields := strings.Split(line[pivot:], ",")      

    for _, value := range fields {
        id, _ := strconv.Atoi(strings.TrimSpace(value))
        var link *Node = getNode_byId(nodes[typ], id)
        if link == nil { link = new_node(id) }  
        addNode(typ, link)  

        append(nod.links[field], link ) 
    }
}
}


func equal_byId( nodeA, nodeB Node) bool {
    return (nodeA.id == nodeB.id)
}

func equal_byProp( nodeA, nodeB Node, property string) bool {
    return (nodeA.props[property] == nodeB.props[property])
}

//========methods on node==========
func (node Node) IsEqual_byId( comparand Node ) bool {
    return equal_byId(node, comparand)
}

func (node Node) IsEqual_byProp( comparand Node, property string ) bool {
    return equal_byProp(node, comparand, property)
}

func (node *Node) addLink (property string, link *Node){
    addLinkToNode( node, link, property)
}

//===================
func main() {
        fmt.Println("hello world")
}

and this is the error I got, I tried my best but I cannot resolve.

$ gccgo elements.go
elements.go:23:19: error: expected ‘)’
elements.go:23:34: error: expected ‘;’ or ‘}’ or newline
elements.go:23:2: error: too many values in return statement
elements.go:91:4: error: value computed is not used

I do not understand where I need to use the semi-colon and why.

0

1 Answer 1

3

The problem, I think, may be in func new_node:

return  &Node( Id, " ", nil, nil)

Should be

return  &Node{Id, " ", nil, nil}

See http://golang.org/ref/spec#Composite_literals

Also, I have a feeling that, in func nodeFromString (line 93-ish):

append(nod.links[field], link)

Should be:

nod.links[field] = append(nod.links[field], link)

Otherwise you'll get an error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.