heloman
V2EX  ›  问与答

什么数据结构即可以有序遍历又可以快速查找?

  •  
  •   heloman · Oct 27, 2015 · 3926 views
    This topic created in 3853 days ago, the information mentioned may be changed or developed.

    要存储的数据格式为(int id, int time, string name),现需要:

    1 , 能够按 time 顺序遍历
    2 , 能够快速使用 id 删除对应的 time 和 name

    请问什么数据结构能够实现这个目标?使用 c#,最好利用自有的数据结构 3q~

    10 replies    2015-10-27 16:37:34 +08:00
    FrankFang128
        1
    FrankFang128  
       Oct 27, 2015
    SQL 数据库哇……
    xi_lin
        2
    xi_lin  
       Oct 27, 2015
    存两份。。
    c742435
        3
    c742435  
       Oct 27, 2015
    存两份靠谱
    wshcdr
        4
    wshcdr  
       Oct 27, 2015
    C# ArrayList
    nathanw
        5
    nathanw  
       Oct 27, 2015
    散列表
    pi1ot
        6
    pi1ot  
       Oct 27, 2015
    听起来类似 memcached ,可以一套数据,两套索引。
    PublicID
        7
    PublicID  
       Oct 27, 2015 via Android
    Time->name RBT
    Id->time RBT/HASH

    数据规模多少?
    heloman
        8
    heloman  
    OP
       Oct 27, 2015
    @nathanw 具体怎么做呢?

    @pi1ot
    @PublicID

    3q ,数据规模应该不超过 10k ,还有忘了说了一点,添加新数据的时间就是 time

    两套索引的办法确实不错!
    如果两套结构的话,倒是想起来一个办法:可以做一个 queue ,按照数据产生时间插入 queue ,再多余存储一个可用 id 的 set ,删除时只删除 set 中的 id ,遍历时检查 id ,如果不在 set 中则从 queue 中删除
    caoyue
        9
    caoyue  
       Oct 27, 2015
    @heloman
    「添加新数据的时间就是 time 」
    或许你可以看看 OrderedDictionary
    WalkingEraser
        10
    WalkingEraser  
       Oct 27, 2015
    Java 的 LinkedHashMap ,(手动斜眼
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2922 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 71ms · UTC 14:27 · PVG 22:27 · LAX 07:27 · JFK 10:27
    ♥ Do have faith in what you're doing.