内存有效的方式来代表最短路径?

编程入门 行业动态 更新时间:2024-10-24 22:26:48
本文介绍了内存有效的方式来代表最短路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

说我得到了从节点A到节点B的最短路径.该路径只是边的列表,因此一条路径A-> B-> C将表示为[(A,B),(B,C)].

Say I am given the shortest path from node A to node B. The path is simply a list of edges, so a path A->B->C, will be represented as [(A,B),(B,C)].

当前,每个节点的类型为 string ,从一个节点到另一个节点(例如(A,B))的路径是字符串的 set ,并且该路径是集合的列表.

Currently, each node is of type string, a path from one node to another, say (A, B), is a set of string, and the path is a list of sets.

现在,该路径包含超过60k的边,必须将其保存到数据库中以供以后检索.

Now, the path consists of over 60k edges, and it must be saved to a database for later retrieval.

因此,很明显,我需要一种非常好的方法来用C ++表示此路径:

So obviously, I need a very nice way to represent this path in C++ such that:

  • 与原始路径相比,路径的大小已大大减小
  • 从数据库检索路径时,检索时间足够短.
  • 谁能为我提供一些见识?

    Can anyone provide me with some insight?

    谢谢.

    推荐答案

    如果您将很多字符串复制到 c ++ 代码中,并且它们很大,则可以考虑使用指针或智能指针.还可以选择对字符串进行哈希处理,但是这对于比较比较有用.通常,为什么首先要担心使用字符串,除非它们非常大,例如文本文档.

    If you copy the strings alot in the c++ code and they are very large you might consider using a pointer or smart pointer instead. There's also the option of hashing the strings, but that will mostly be usefull for comparisons. Generally why worry about using strings in the first place, except if they are very large like text documents.

    对于容器,您可以只使用 std :: vector< std :: string>

    As for container, you could just use a std::vector<std::string>

    最后存储A到B的最短路径的最有效方法是存储端点,然后仅在需要时才计算结果.

    The most efficient way of storing the shortest path of A to B in the end is just storing the end points, then only calculate the result when needed.

    更多推荐

    内存有效的方式来代表最短路径?

    本文发布于:2023-11-29 23:24:34,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1647947.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:最短   路径   内存   代表   方式

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!