-
Notifications
You must be signed in to change notification settings - Fork 64
/
Set.txt
178 lines (134 loc) · 6.11 KB
/
Set.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
*vital/Data/Set.txt* set library.
Maintainer: haya14busa <hayabusa1419@gmail.com>
==============================================================================
CONTENTS *Vital.Data.Set-contents*
INTRODUCTION |Vital.Data.Set-introduction|
INTERFACE |Vital.Data.Set-interface|
FUNCTIONS |Vital.Data.Set-functions|
Set Object |Vital.Data.Set-Set|
==============================================================================
INTRODUCTION *Vital.Data.Set-introduction*
*Vital.Data.Set* is Collection Utilities Library.
It provides set and frozenset data structure ported from python.
https://docs.python.org/3.4/library/stdtypes.html#set-types-set-frozenset
>
let s:V = vital#{plugin-name}#new()
let s:Set = s:V.import("Data.Set")
let set = s:Set.set([1,1,2,3,4,4,5])
echo set.to_list() | " => [1,2,3,4,5]
call set.add(4)
echo set.to_list() | " => [1,2,3,4,5]
call set.add(6)
echo set.to_list() | " => [1,2,3,4,5,6]
echo set.sub([1,2,3]).to_list() | " => [4,5,6]
let frozenset = s:Set.frozenset([1,1,2,3,4,4,5])
echo frozenset.to_list() | " => [1,2,3,4,5]
" frozenset does not have mutable methods
call frozenset.add(6)
" => E716: Key not present in Dictionary: add
<
==============================================================================
INTERFACE *Vital.Data.Set-interface*
------------------------------------------------------------------------------
FUNCTIONS *Vital.Data.Set-functions*
set([{list}], [{hashfunc}]) *Vital.Data.Set.set()*
Returns a new 'Set' object.
frozenset([{list}], [{hashfunc}]) *Vital.Data.Set.frozen()*
Returns a new 'Frozen' object which has not mutable methods
(|Vital.Data.Set-Set-mutable|).
{hashfunc} is used to hash the value for identifying each element.
Example: >
function! s:my_hash_func(x) abort
return tolower(a:x)
endfunction
echo s:Set.set(['a', 'ab', 'A']).to_list()
" => ['A', 'ab', 'a']
echo s:Set.set(['a', 'ab', 'A'], function('s:my_hash_func')).to_list()
" => ['ab', 'a']
<
------------------------------------------------------------------------------
Set Object *Vital.Data.Set-Set*
Set.to_list() *Vital.Data.Set-Set.to_list()*
Converts to |List|.
Set.in({elem}) *Vital.Data.Set-Set.in()*
Checks if there is {elem} in the set. This returns boolean value.
Set.union({other}) *Vital.Data.Set-Set.union()*
Set.or({other}) *Vital.Data.Set-Set.or()*
Return a new set with elements from the set and {other}.
Set.intersection({other}) *Vital.Data.Set-Set.intersection()*
Set.and({other}) *Vital.Data.Set-Set.and()*
Return a new set with elements common to the set and {other}.
Set.symmetric_difference({other}) *Vital.Data.Set-Set.symmetric_difference()*
Set.xor({other}) *Vital.Data.Set-Set.xor()*
Return a new set with elements in either the set or {other} but not
both.
Set.difference({other}) *Vital.Data.Set-Set.difference()*
Set.sub({other}) *Vital.Data.Set-Set.sub()*
Return a new set with elements in the set that are not in {other}.
Set.issubset({other}) *Vital.Data.Set-Set.issubset()*
Set.le({other}) *Vital.Data.Set-Set.le()*
Test whether every element in the set is in {other}.
Set.lt({other}) *Vital.Data.Set-Set.lt()*
Test whether the set is a proper subset of {other}, that is, >
set.le(other) && set != other
Set.issuperset({other}) *Vital.Data.Set-Set.issuperset()*
Set.ge({other}) *Vital.Data.Set-Set.ge()*
Test whether every element in {other} is in the set.
Set.gt({other}) *Vital.Data.Set-Set.gt()*
Test whether the set is a proper superset of {other}, that is, >
set.ge(other) && set != other
Set.len() *Vital.Data.Set-Set.len()*
Return the length of Set.
------------------------------------------------------------------------------
Mutable Set Object *Vital.Data.Set-Set-mutable*
The following methods for set do not apply to immutable instances of
|Vital.Data.Set.frozen()|
Set.update({other}) *Vital.Data.Set-Set.update()*
Set.ior({other}) *Vital.Data.Set-Set.ior()*
Update the set, adding elements from {other}.
Set.intersection_update({other}) *Vital.Data.Set-Set.intersection_update()*
Set.iand({other}) *Vital.Data.Set-Set.iand()*
Update the set, keeping only elements found in it and {other}.
Set.difference_update({other}) *Vital.Data.Set-Set.difference_update()*
Set.isub({other}) *Vital.Data.Set-Set.isub()*
Update the set, removing elements found in {other}.
Set.symmetric_difference_update({other})
*Vital.Data.Set-Set.symmetric_difference_update()*
Set.ixor({other}) *Vital.Data.Set-Set.ixor()*
Update the set, keeping only elements found in either set, but not in
both.
Set.add({elem}) *Vital.Data.Set-Set.add()*
Add {elem} to the set.
Set.remove({elem}) *Vital.Data.Set-Set.remove()*
Remove {elem} from the set. Throw >
vital: Data.Set: the element is not a member
< if {elem} is not contained in the set.
Set.discard({elem}) *Vital.Data.Set-Set.discard()*
Remove {elem} from the set if it is present.
Set.pop() *Vital.Data.Set-Set.pop()*
Remove and return an arbitrary element from the set. Throw >
vital: Data.Set: set is empty
< if the set is empty.
Set.clear() *Vital.Data.Set-Set.clear()*
Remove all elements from the set.
Note: {other} will accept 'Set' object or |List| as an argument.
ior(), iand(), isub(), ixor() return Set object. 'i' is short for
"in-place", they are mutable version of or(), and(), sub(), xor()
respectively.
Note: If return value is 'Set' object, the type of returned 'Set'
object is same as type of the instance. Example:
>
let set = s:Set.set(['a', 'ab', 'A'], function('s:my_hash_func'))
echo set.to_list() | " => ['ab', 'a']
" {comparefunc} will be same as `set`
let set2 = set.or(['aB', 'c'])
echo set2.to_list() | " => ['ab', 'a', 'c']
let frozenset = s:Set.frozenset([1,2,3])
" returned 'Set' object is frozenset
let frozenset2 = frozenset.and(s:Set.set([2,3,4]))
echo frozenset2.to_list() | " => [2,3]
call frozenset.add(6)
" => E716: Key not present in Dictionary: add
<
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl