Multiset data structure - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Operations : Sets and lists : hashmset

hashmset - Multiset data structure

Calling Sequence

hashmset[new]( v1 = m1, v2 = m2, ..., vk = mk )

hashmset[new]( [ v1, m1 ], [ v2, m2 ], ..., [ vk, mk ] )

hashmset[empty]( s )

hashmset[entries]( s )

hashmset[members]( s )

hashmset[insert]( v, m, s )

hashmset[insert]( v = m, s )

hashmset[remove]( v = m, s )

hashmset[remove]( v, m, s )

hashmset[`subset`]( s, t )

hashmset[`intersect`]( s, t )

hashmset[`union`]( s, t )

hashmset[`minus`]( s, t )

hashmset[symdif]( s, t )

Parameters

v, v1, v2, ..., vk

-

anything; values to be inserted into, or removed from, the multiset

m, m1, m2, ..., mk

-

posint; multiplicities of corresponding values

s, t

-

name; multiset

Description

• 

The hashmset package provides an implementation of multisets. A multiset is an unordered collection of objects, in which objects can appear more than once. The number of occurrences of an object in a multiset is called its ``multiplicity''.

• 

The new command returns a new multiset with the specified values and multiplicities. If called with no arguments, the returned multiset is empty.

• 

The empty command tests whether s is an empty multiset. If the multiset s is empty, the empty function returns true. Otherwise, it returns false.

• 

The entries command returns a list of pairs of the form v,m, in which v is an expression in the multiset s, and m is its multiplicity.

• 

The members command returns the set of expressions that appear in the multiset s. It does not return information about their respective multiplicities.

• 

The insert command adds a new element v to the multiset s or, if v is an element in s, increases the multiplicity of v in s. The multiplicity of v in s increases by the positive integer m.

• 

The remove command deletes an element v from the multiset s, or, if m is less than the multiplicity of v in s, reduces the multiplicity of v in s. The multiplicity of v is reduced by the positive integer m.

• 

The subset operator tests whether the multiset s (its first argument) is a proper sub-multiset of the multiset t (its second argument).

• 

The intersect operator computes the intersection of the multisets s and t.

• 

The union operator computes the union -- as multisets -- of s and t.

• 

The symdif command computes the symmetric difference of s and t.

• 

The minus operator computes the multiset difference of s and t.

• 

Because many hashmset export names (functions and operators) match global function and operator names, it is recommended that you use the long form of the hashmset package names, for example, hashmset[export_name] or hashmset:-export_name.

Examples

s:=hashmset:-newa,2,b,3:

hashmset:-entriess

a,2,b,3

(1)

hashmset:-memberss

a,b

(2)

hashmset:-emptys

false

(3)

hashmset:-inserta=2,s

4

(4)

hashmset:-entriess

a,4,b,3

(5)

hashmset:-insertc=2,s

2

(6)

hashmset:-entriess

a,4,c,2,b,3

(7)

hashmset:-removea=3,s

hashmset:-entriess

a,1,c,2,b,3

(8)

t:=hashmset:-newa=2,b=4,c=3,d=1:

usehashmsetins⊆t;entriess∩t;entriess∪t;entriest∖send use

a,1,d,1,c,1,b,1

(9)

entrieshashmset:-symdifs,t

1,1,1,1

(10)

See Also

convert/multiset, Long Form Names, priqueue, queue, stack, use


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam