Giter Site home page Giter Site logo

multiset's Introduction

multiset Build Status

A simple multiset/bag implementation for Clojure.

Usage

Installation via Leiningen

Add this to your :depependencies:

Clojars Project

The current API docs are here: http://achim.github.io/multiset

Example usage

Define some multisets

user=> (require '[multiset.core :as ms])
nil
user=> (def a (ms/multiset 1 2 4 5 4 2 7))
#'user/a
user=> (def b (ms/multiset 4 5 6 6 9))
#'user/b
user=> (def c (ms/multiset 1 2 4 7))
#'user/c

Basic functionality

user=> a
#{7 5 4 4 2 2 1}
user=> (contains? a 3)
false
user=> (contains? a 2)
true
user=> (disj a 2)
#{7 5 4 4 2 1}
user=> (conj a 4)
#{7 5 4 4 4 2 2 1}
user=> (a 2)

Multiset-specific stuff

user=> (ms/multiset? a)
true
user=> (ms/multiplicities a)
{7 1, 5 1, 4 2, 2 2, 1 1}
user=> (ms/multiplicity a 3)
0
user=> (ms/multiplicity a 2)
2

Multiset operators

user=> (ms/intersect a (conj b 4))
#{5 4 4}
user=> (ms/union a b)
#{1 2 2 4 4 5 6 6 7 9}
user=> (ms/sum a b)
#{1 2 2 4 4 4 5 5 6 6 7 9}
user=> (ms/minus a b)
#{7 4 2 2 1}
user=> (ms/scale a 3)
#{7 7 7 5 5 5 4 4 4 4 4 4 2 2 2 2 2 2 1 1 1}
user=> (ms/cartprod a b)
#{[5 4] [7 6] [7 6] [4 4] [4 4] [5 5] [4 5] [4 5] [5 6] [5 6] [2 4] [2 4] [4 6] [4 6] [4 6] [4 6] [7 9] [2 5] [2 5] [1 4] [2 6] [2 6] [2 6] [2 6] [5 9] [1 5] [4 9] [4 9] [1 6] [1 6] [2 9] [2 9] [1 9] [7 4] [7 5]}
user=> (ms/subset? a b)
false
user=> (ms/subset? c a)
true
user=> (ms/subset? (ms/multiset 2 2 2) a)
false

License

Copyright (C) 2012โ€“2015 Achim Passen and contributors.

Distributed under the Eclipse Public License. See COPYING.

multiset's People

Contributors

achim avatar gfredericks avatar hypirion avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.