SML/NJ:如何使用HashTable? [英] SML/NJ: How to use HashTable?

查看:182
本文介绍了SML/NJ:如何使用HashTable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很想在SML中创建一个HashTable,似乎在SML/NJ中已经有一个用于此的结构.

I really want to create a HashTable in SML, it seems there already is a structure for this in SML/NJ.

问题是,我该如何使用它?我还没有完全理解如何在SML中使用结构,并且在我读过的书中一些非常基本的示例给了我什至不知道如何更正的错误,因此使用HashTable结构可能很容易,但是我不知道如果有人可以解释这一点,那也太好了!

The question is, how do I use it? I've not fully understood how to use structures in SML, and some of the very basic examples in the book I read gives me errors I don't even know how to correct, so using the HashTable structure might be an easy thing, but I wouldn't know. If someone could explain this, then that'd be wonderful too!

我在想是这样的:

val ht : string * int HashTable.hash_table = HashTable.mkTable();

???

推荐答案

mkTable值的签名为:

val mkTable : (('a -> word) * (('a * 'a) -> bool)) -> (int * exn)
      -> ('a,'b) hash_table
    (* Given a hashing function and an equality predicate, create a new table;
     * the int is a size hint and the exception is to be raised by find.
     *)

因此,您将必须执行以下操作:

Therefore, you would have to do something like:

val ht : (string, int) HashTable.hash_table =
    HashTable.mkTable (HashString.hashString, op=) (42, Fail "not found")

这篇关于SML/NJ:如何使用HashTable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆