New answers tagged

2

Just some remarks, I didn't review every method... Concise API As an API for creating and querying graphs, DirectedGraph could be more focussed. E.g. there are too many different methods for adding nodes or edges to the graph. More is not always better. Example questions: Do you need graphs with isolated nodes (no connecting edges)? If not, having the ...


2

I have no experience with any of these libraries, so I can only comment on aspects of the language itself. def insert_data(): if not db: raise Exception('db object not defined') Just to be clear, if db truly hasn't been assigned at this point, you cannot use if not db to check for that. Attempting to use a name before it's been associated with ...


5

FMc has made some excellent points. I'll try not to repeat those. Vertices You determine the list of vertices using: source_vertices = [column[0] for column in graph] destination_vertices = [column[1] for column in graph] vertices = list(set(source_vertices) | set(destination_vertices)) and then repeatedly use len(vertices) through-out your ...


6

Your program provides a good example for seeing how one can increase code readability through some common techniques: (1) convenience variables to avoid verbose repetition; (2) code organized as small commented "paragraphs" or blocks; and (3) the use of shorter variables names to lighten the visual weight of the code, thus enhancing ease of reading ...


5

Am I going too far/extreme trying to place data onto the heap? Yes. Containers like std::unordered_map and std::forward_list already store contents on the heap. If you declare a std::unordered_map on the stack, only a little bit of administrative data goes on the stack. But the same happens with std::unique_ptr. So in your code, the use of std::unique_ptr ...


Top 50 recent answers are included