【问题标题】:Using ORD_MAP as a hash table in SML/NJ在 SML/NJ 中使用 ORD_MAP 作为哈希表
【发布时间】:2012-08-25 08:08:07
【问题描述】:

我正在尝试在 ML 中实现类似于哈希表的东西,但我想使用列表作为键。我想我可以使用 ORD_MAP 结构,但我想为 ORD_KEY 签名提供我自己的结构,这样我就可以使用列表作为 ord_keys,但我找不到办法。怎么可能?

【问题讨论】:

    标签: hashmap structure signature smlnj


    【解决方案1】:

    ORD_MAP 和 ORD_KEY 是签名。如果您希望能够使用地图,则需要特定的实现。例如:

    structure Key =
      struct
        type ord_key = int
        val compare = Int.compare
      end
    structure Map = RedBlackMapFn (Key)
    

    那么,你可以这样做:

      - Map.singleton (1, "foo");
       val it = - : string map
       - Map.find (it, 1);
       val it = SOME "foo" : string option
       -   
    

    希望对您有所帮助!这些接口的文档是: http://www.smlnj.org/doc/smlnj-lib/Manual/toc.html

    【讨论】:

      【解决方案2】:

      我认为可以回答您问题的一个例子是康奈尔大学的讲座: Cornell's Lecture

      【讨论】:

        猜你喜欢
        • 2013-11-19
        • 1970-01-01
        • 2017-11-06
        • 2014-03-19
        • 1970-01-01
        • 2010-09-16
        • 1970-01-01
        • 2010-10-23
        • 1970-01-01
        相关资源
        最近更新 更多