1

I'm looking for a way to retrieve a node using an identifier, using only the Guava library. I prefer not to use an external HashSet, which I have considered, because my dataset is too big.

I would like a way to index all of my graph nodes using an index, using a String or integer type, and be later able to retrieve my nodes efficiently.

Right now I could iterate over the nodes set of my MutableGraph, and check for object equality, like this :

    MutableGraph<CategoryNode> wikiGraph = GraphBuilder.directed().build();
    for (MyNode node : wikiGraph.nodes()) {
        if(node.equals(new MyNode("myStringIndex"))) {
            // object found !
            return node;
        }
    }

But this is highly inefficient if the number of nodes gets big. Is there a built-in solution for indexing graph nodes in Guava or do I need to use another library ?

  • Any library would probably also use a HashSet or similar. Go ahead and use it. – Sean Patrick Floyd May 17 '18 at 17:56
  • 1
    I'm not entirely sure I understand what you're after. Would a collection-indexing solution like [CQEngine](https://github.com/npgall/cqengine) or a more memory-efficient set implementation like [fastutil](http://fastutil.di.unimi.it/)'s, [Koloboke](https://koloboke.com/)'s or [Eclipse Collections](https://www.eclipse.org/collections/)' help? – jbduncan May 17 '18 at 19:54
  • @jbduncan Yes absolutely. Thanks for your help, I was looking for a built-in Guava solution but this will do the trick. – Jean-Pierre Coffe May 18 '18 at 08:37
  • If you could post your answer down below, I will accept it as the solution and close the topic – Jean-Pierre Coffe May 18 '18 at 08:49
  • @Jean-PierreCoffe Done. :) – jbduncan May 18 '18 at 20:39

1 Answers1

1

If you're looking for a way to index your graph nodes, sadly Guava doesn't have this feature built in. Consider using CQEngine, which by my understanding allows you to do this for any collection (such as a set of graph nodes).

Alternatively, if you're just looking for a more memory-efficient set implementation, there is a wide range of options including but not limited to Koloboke, fastutil and Eclipse Collections.

jbduncan
  • 425
  • 9
  • 17