zoukankan      html  css  js  c++  java
  • Haskell语言学习笔记(77)Data.HashSet

    安装 unordered-containers

    $ cabal install unordered-containers
    Installed unordered-containers-0.2.9.0
    Prelude> import Data.HashSet as HashSet
    Prelude HashSet> :set -XOverloadedLists
    Prelude HashSet>
    

    Construction

    Prelude HashSet> empty
    fromList []
    Prelude HashSet> singleton "a"
    fromList ["a"]
    

    Combine

    Prelude HashSet> union [3,4,5] [4,5,6]
    fromList [3,4,5,6]
    Prelude HashSet> unions [[3,4,5],[4,5,6]]
    fromList [3,4,5,6]
    

    Basic interface

    Prelude HashSet> HashSet.null empty
    True
    Prelude HashSet> HashSet.null [3]
    False
    Prelude HashSet> size [3,5,7]
    3
    Prelude HashSet> member 3 [3,5]
    True
    Prelude HashSet> insert 3 [5,7]
    fromList [3,5,7]
    Prelude HashSet> delete 3 [3,5,7]
    fromList [5,7]
    

    Transformations

    Prelude HashSet> HashSet.map (+2) [1..6]
    fromList [3,4,5,6,7,8]
    

    Difference and intersection

    Prelude HashSet> difference [3,4,5] [4,5,6]
    fromList [3]
    Prelude HashSet> intersection [3,4,5] [4,5,6]
    fromList [4,5]
    

    Folds

    Prelude HashSet> HashSet.foldl' (+) 0 [1..6]
    21
    Prelude HashSet> HashSet.foldr (+) 0 [1..6]
    21
    

    Lists

    Prelude HashSet> toList [1..6]
    [1,2,3,4,5,6]
    Prelude HashSet> fromList [1..6]
    fromList [1,2,3,4,5,6]
    

    Maps

    Prelude HashSet> import Data.HashMap.Lazy as HashMap
    Prelude HashSet HashMap> toMap [3,4,5]
    fromList [(3,()),(4,()),(5,())]
    Prelude HashSet HashMap> fromMap [(3,()),(4,()),(5,())]
    fromList [3,4,5]
    
  • 相关阅读:
    链接器之库文件处理
    Yii2.0数据库查询的一些简单的操作
    Yii rules常用规则
    yii2 session的使用方法
    curl实现发送Get和Post请求(PHP)
    Yii2.0登录详解(下)
    Yii2.0 用户登录详解(上)
    Linux终端最常用快捷键
    PHP5.6启动失败
    MySQL的外键是什么和它的作用
  • 原文地址:https://www.cnblogs.com/zwvista/p/9256626.html
Copyright © 2011-2022 走看看