delete dfs or not?

32 views
Skip to first unread message

frank....@gmail.com

unread,
Feb 11, 2016, 8:37:45 AM2/11/16
to Sparksee
Hi,
following the example here: http://sparsity-technologies.com/UserManual/API.html#api, I put, in an already opened session, this:
    oid_t src = 1; // source node identifier
    TraversalDFS dfs(*sess, src);
    dfs.AddAllEdgeTypes(Outgoing);
    dfs.SetMaximumHops(3);
    while (dfs.HasNext())
    {
      std::cout << "Current node " << dfs.Next()
                << " at depth " << dfs.GetCurrentDepth() << std::endl;
    }
    delete dfs;
When compiling it says:
marco@pc:~/sparkseecpp-5.2.0/urlsGraph$ g++ -O3 -std=c++11 -I ../includes/sparksee UrlsGraph.cpp -oUrlsGraph -L ../lib/linux64 -lsparksee
UrlsGraph.cpp: In function ‘int main(int, char**)’:
UrlsGraph.cpp:146:12: error: type ‘class sparksee::algorithms::TraversalDFS’ argument given to ‘delete’, expected pointer
     delete dfs;

If commenting delete dfs; 
marco@pc:~/sparkseecpp-5.2.0/urlsGraph$ g++ -O3 -std=c++11 -I ../includes/sparksee UrlsGraph.cpp -oUrlsGraph -L ../lib/linux64 -lsparksee
marco@pc:~/sparkseecpp-5.2.0/urlsGraph$ export LD_LIBRARY_PATH=/home/marco/sparkseecpp-5.2.0/lib/linux64/
marco@pc:~/sparkseecpp-5.2.0/urlsGraph$ time ./UrlsGraph
Traversal Algorithms:
terminate called after throwing an instance of 'sparksee::gdb::WrongArgumentError'
**** CRITICAL ERROR (SIGNAL NUM 6)
------- Begin of call stack ------
/home/marco/sparkseecpp-5.2.0/lib/linux64/libsparksee.so(_ZN13sparksee_core21CallStackTraceHandler13SignalHandlerEi+0x28) [0x7f4e078c59a8]
/lib/x86_64-linux-gnu/libc.so.6(+0x36d40) [0x7f4e06ed8d40]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x39) [0x7f4e06ed8cc9]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x148) [0x7f4e06edc0d8]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x15d) [0x7f4e074e76dd]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x67746) [0x7f4e074e5746]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x67791) [0x7f4e074e5791]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x679a8) [0x7f4e074e59a8]
/home/marco/sparkseecpp-5.2.0/lib/linux64/libsparksee.so(_ZN8sparksee10algorithms9Traversal16AssertAddedNodesEv+0x82) [0x7f4e078a7fc2]
/home/marco/sparkseecpp-5.2.0/lib/linux64/libsparksee.so(_ZN8sparksee10algorithms12TraversalDFS4NextEv+0x23) [0x7f4e078aaab3]
./UrlsGraph() [0x402bb1]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f4e06ec3ec5]
./UrlsGraph() [0x402ef0]
-------- End of call stack -------
Annullato

So...when using delete dfs it says "expected pointer":
UrlsGraph.cpp:146:12: error: type ‘class sparksee::algorithms::TraversalDFS’ argument given to ‘delete’, expected pointer
     delete dfs;

and when removing the delete dfs; when executing the file, errors indicating a missing "delete" arise...

What do I have to do ?

Frank

c3po.ac

unread,
Feb 11, 2016, 9:50:44 AM2/11/16
to Sparksee
Hi,

You may be getting the wrong argument error because you are using an invalid oid as the source node.

Instead of setting the oid value explicitly to any value (1 in this case), you should get the oid value for the node that you are looking for.
There are several methods to get the node: using a FindObject with an unique attribute value, keeping the oid returned when the node was added, getting the oid from an objects iterator, ...

For example:

    attr_t nameAttrId = graph->FindAttribute(peopleTypeId, L"NAME");
     v
.SetString(L"Bill Murray");
     oid_t src
= graph->FindObject(nameAttrId, v);


The TraversalDFS must be deleted before the session is commited or closed.
In the sample code, the delete is not explicitly called because the TraversalDFS instance is created in the stack and will automatically be deleted when the function returns. But if you don't have this code in a function different than the one where you close the session, you may be closing the session before the dfs is deleted.

So a better sample code could have been this one, allocating the dfs instance with the "new" operator and explicitly deleting it:

TraversalDFS *dfs = new TraversalDFS(*sess, src);
dfs
->AddAllEdgeTypes(Outgoing);
dfs
->AddNodeType(graph->FindType(L"PEOPLE"));
dfs
->SetMaximumHops(3);
while (dfs->HasNext())
{
    std
::cout << "Current node " << dfs->Next()
                   
<< " at depth " << dfs->GetCurrentDepth() << std::endl;
}
delete dfs;

I hope this helps.

Best regards

El dijous, 11 febrer de 2016 14:37:45 UTC+1, frank....@gmail.com va escriure:

frank....@gmail.com

unread,
Feb 12, 2016, 2:44:47 AM2/12/16
to spar...@googlegroups.com
Il giorno giovedì 11 febbraio 2016 15:50:44 UTC+1, c3po.ac ha scritto:
Hi,

You may be getting the wrong argument error because you are using an invalid oid as the source node.

Instead of setting the oid value explicitly to any value (1 in this case), you should get the oid value for the node that you are looking for.
There are several methods to get the node: using a FindObject with an unique attribute value, keeping the oid returned when the node was added, getting the oid from an objects iterator, ...

For example:

    attr_t nameAttrId = graph->FindAttribute(peopleTypeId, L"NAME");
     v
.SetString(L"Bill Murray");
     oid_t src
= graph->FindObject(nameAttrId, v);

Based on your next hints, I made it work in this way:
    oid_t src = url_01;
    TraversalDFS *dfs = new TraversalDFS(*sess, url_01);
    dfs->AddAllEdgeTypes(Outgoing);
    dfs->AddNodeType(g->FindType(L"URL"));
    dfs->SetMaximumHops(3);
    while (dfs->HasNext())
    {
      std::wcout << "Current node " << dfs->Next()
                  << " at depth " << dfs->GetCurrentDepth() << std::endl;
    }
    delete dfs;
 
But when getting the oid value of the node, I'm having some errors messages again:
   Value *value = new Value(); 
   attr_t nameAttrId = g->FindAttribute(UrlName, L"NAME");
    value->SetString(L"http://www.....htm");
    oid_t src = g->FindObject(nameAttrId, *value);

terminate called after throwing an instance of 'sparksee::gdb::Error'
**** CRITICAL ERROR (SIGNAL NUM 6)
------- Begin of call stack ------
/sparkseecpp-5.2.0/lib/linux64/libsparksee.so(_ZN13sparksee_core21CallStackTraceHandler13SignalHandlerEi+0x28) [0x7f22d8cb89a8]
/lib/x86_64-linux-gnu/libc.so.6(+0x36d40) [0x7f22d82cbd40]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x39) [0x7f22d82cbcc9]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x148) [0x7f22d82cf0d8]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x15d) [0x7f22d88da6dd]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x67746) [0x7f22d88d8746]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x67791) [0x7f22d88d8791]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x679a8) [0x7f22d88d89a8]
/home/marco/sparkseecpp-5.2.0/lib/linux64/libsparksee.so(_ZN8sparksee3gdb5Graph10FindObjectEiRNS0_5ValueE+0x6c) [0x7f22d8c71a1c]
./UrlsGraph() [0x4029f5]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f22d82b6ec5]
./UrlsGraph() [0x402eff]
-------- End of call stack -------


I guess something is wroing in deferencing the pointer: *value
Could you please clarify me this?
Frank

frank....@gmail.com

unread,
Feb 12, 2016, 3:06:02 AM2/12/16
to Sparksee

c3po.ac

unread,
Feb 15, 2016, 3:25:42 AM2/15/16
to Sparksee


Hi,

The problem is that the DFS requires at least one edge type. You are setting it to use all the edge types, but your database does not have any edge types defined, so it's throwing the wrong argument exception because not all the required input settings have been satisfied.

Once you have created at least one edge type, even if you don't create any edge, the algorithm should work.

For example, you can just add this code:
    // Edges:
    type_t
AnEdgeType = g->NewEdgeType(L"An endge name", false, true);

Best regards

El divendres, 12 febrer de 2016 9:06:02 UTC+1, frank....@gmail.com va escriure:

frank....@gmail.com

unread,
Feb 15, 2016, 7:01:27 AM2/15/16
to Sparksee
Thank you a lot.
Frank
Reply all
Reply to author
Forward
0 new messages