@shd101wyy/yo 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -1
- package/out/cjs/index.cjs +581 -601
- package/out/cjs/yo-cli.cjs +739 -733
- package/out/cjs/yo-lsp.cjs +11615 -0
- package/out/esm/index.mjs +530 -550
- package/out/types/src/cache.d.ts +2 -0
- package/out/types/src/codegen/exprs/return.d.ts +1 -1
- package/out/types/src/codegen/types/generation.d.ts +0 -2
- package/out/types/src/codegen/utils/index.d.ts +2 -8
- package/out/types/src/doc/extractor.d.ts +4 -0
- package/out/types/src/evaluator/builtins/rc-fns.d.ts +0 -5
- package/out/types/src/evaluator/context.d.ts +7 -3
- package/out/types/src/evaluator/trait-checking.d.ts +2 -0
- package/out/types/src/evaluator/types/object.d.ts +2 -1
- package/out/types/src/evaluator/types/struct.d.ts +2 -1
- package/out/types/src/evaluator/types/utils.d.ts +3 -8
- package/out/types/src/evaluator/values/impl.d.ts +9 -1
- package/out/types/src/expr.d.ts +1 -2
- package/out/types/src/function-value.d.ts +1 -0
- package/out/types/src/lsp/completion.d.ts +3 -0
- package/out/types/src/lsp/definition.d.ts +3 -0
- package/out/types/src/lsp/diagnostics.d.ts +6 -0
- package/out/types/src/lsp/document-manager.d.ts +31 -0
- package/out/types/src/lsp/folding.d.ts +3 -0
- package/out/types/src/lsp/hover.d.ts +3 -0
- package/out/types/src/lsp/inlay-hints.d.ts +3 -0
- package/out/types/src/lsp/references.d.ts +3 -0
- package/out/types/src/lsp/rename.d.ts +16 -0
- package/out/types/src/lsp/server.d.ts +1 -0
- package/out/types/src/lsp/signature-help.d.ts +3 -0
- package/out/types/src/lsp/symbols.d.ts +3 -0
- package/out/types/src/lsp/utils.d.ts +11 -0
- package/out/types/src/tests/lsp.test.d.ts +1 -0
- package/out/types/src/tests/version.test.d.ts +1 -0
- package/out/types/src/types/creators.d.ts +2 -3
- package/out/types/src/types/definitions.d.ts +3 -6
- package/out/types/src/types/guards.d.ts +5 -2
- package/out/types/src/types/tags.d.ts +0 -1
- package/out/types/src/version-cache.d.ts +7 -0
- package/out/types/src/version.d.ts +5 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
- package/scripts/build-site.ts +32 -15
- package/scripts/check-liburing.js +2 -2
- package/std/imm/list.yo +254 -0
- package/std/imm/map.yo +917 -0
- package/std/imm/set.yo +179 -0
- package/std/imm/sorted_map.yo +595 -0
- package/std/imm/sorted_set.yo +202 -0
- package/std/imm/string.yo +667 -0
- package/std/imm/vec.yo +456 -0
- package/std/prelude.yo +22 -5
- package/std/sync/channel.yo +92 -44
- package/std/sync/cond.yo +5 -1
- package/std/sync/mutex.yo +5 -1
- package/std/sync/once.yo +2 -1
- package/std/sync/rwlock.yo +2 -1
- package/std/sync/waitgroup.yo +2 -1
- package/out/types/src/codegen/exprs/arc.d.ts +0 -5
- package/out/types/src/evaluator/calls/arc.d.ts +0 -15
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
//! Persistent immutable sorted set using a left-leaning red-black tree.
|
|
2
|
+
//!
|
|
3
|
+
//! `SortedSet(T)` is a thin wrapper around `SortedMap(T, bool)`, keeping
|
|
4
|
+
//! elements in sorted order. All mutations return new sets, leaving the
|
|
5
|
+
//! original unchanged.
|
|
6
|
+
//!
|
|
7
|
+
//! Elements must implement `Eq`, `Ord`, and `Send`.
|
|
8
|
+
//!
|
|
9
|
+
//! # Examples
|
|
10
|
+
//!
|
|
11
|
+
//! ```rust
|
|
12
|
+
//! { SortedSet } :: import "std/imm/sorted_set";
|
|
13
|
+
//!
|
|
14
|
+
//! s := SortedSet(i32).new();
|
|
15
|
+
//! s = s.insert(i32(3));
|
|
16
|
+
//! s = s.insert(i32(1));
|
|
17
|
+
//! s = s.insert(i32(2));
|
|
18
|
+
//! // elements are always sorted: 1, 2, 3
|
|
19
|
+
//! ```
|
|
20
|
+
|
|
21
|
+
{ SortedMap } :: import "./sorted_map.yo";
|
|
22
|
+
{ List } :: import "./list.yo";
|
|
23
|
+
|
|
24
|
+
/// Persistent immutable sorted set backed by a left-leaning red-black tree.
|
|
25
|
+
SortedSet :: (fn(comptime(T) : Type, where(T <: (Eq(T), Ord(T), Send))) -> comptime(Type))(
|
|
26
|
+
struct(_inner : SortedMap(T, bool))
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
impl(forall(T : Type), where(T <: (Eq(T), Ord(T), Send)), SortedSet(T),
|
|
30
|
+
/// Create an empty sorted set.
|
|
31
|
+
new : (fn() -> Self)(
|
|
32
|
+
Self(_inner: SortedMap(T, bool).new())
|
|
33
|
+
),
|
|
34
|
+
|
|
35
|
+
/// Number of elements.
|
|
36
|
+
len : (fn(self: Self) -> usize)(self._inner.len()),
|
|
37
|
+
|
|
38
|
+
/// Check if the set is empty.
|
|
39
|
+
is_empty : (fn(self: Self) -> bool)(self._inner.is_empty()),
|
|
40
|
+
|
|
41
|
+
/// Check if the set contains `elem`.
|
|
42
|
+
contains : (fn(self: Self, elem: T) -> bool)(
|
|
43
|
+
self._inner.contains_key(elem)
|
|
44
|
+
),
|
|
45
|
+
|
|
46
|
+
/// Return a new set with `elem` added.
|
|
47
|
+
insert : (fn(self: Self, elem: T) -> Self)(
|
|
48
|
+
Self(_inner: self._inner.insert(elem, true))
|
|
49
|
+
),
|
|
50
|
+
|
|
51
|
+
/// Return a new set with `elem` removed.
|
|
52
|
+
remove : (fn(self: Self, elem: T) -> Self)(
|
|
53
|
+
Self(_inner: self._inner.remove(elem))
|
|
54
|
+
),
|
|
55
|
+
|
|
56
|
+
/// Get the minimum element.
|
|
57
|
+
min : (fn(self: Self) -> Option(T))(
|
|
58
|
+
self._inner.min_key()
|
|
59
|
+
),
|
|
60
|
+
|
|
61
|
+
/// Get the maximum element.
|
|
62
|
+
max : (fn(self: Self) -> Option(T))(
|
|
63
|
+
self._inner.max_key()
|
|
64
|
+
),
|
|
65
|
+
|
|
66
|
+
/// Return elements as a sorted List.
|
|
67
|
+
to_list : (fn(self: Self) -> List(T))(
|
|
68
|
+
self._inner.keys()
|
|
69
|
+
),
|
|
70
|
+
|
|
71
|
+
/// Return the union of two sorted sets.
|
|
72
|
+
union : (fn(self: Self, other: Self) -> Self)({
|
|
73
|
+
elems := other.to_list();
|
|
74
|
+
(result : Self) = self;
|
|
75
|
+
(cur : List(T)) = elems;
|
|
76
|
+
(done : bool) = false;
|
|
77
|
+
while runtime(!(done)), {
|
|
78
|
+
match(cur.head(),
|
|
79
|
+
.Some(elem) => {
|
|
80
|
+
result = result.insert(elem);
|
|
81
|
+
cur = cur.tail();
|
|
82
|
+
},
|
|
83
|
+
.None => {
|
|
84
|
+
done = true;
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
result
|
|
89
|
+
}),
|
|
90
|
+
|
|
91
|
+
/// Return the intersection of two sorted sets.
|
|
92
|
+
intersection : (fn(self: Self, other: Self) -> Self)({
|
|
93
|
+
elems := self.to_list();
|
|
94
|
+
(result : Self) = Self.new();
|
|
95
|
+
(cur : List(T)) = elems;
|
|
96
|
+
(done : bool) = false;
|
|
97
|
+
while runtime(!(done)), {
|
|
98
|
+
match(cur.head(),
|
|
99
|
+
.Some(elem) => {
|
|
100
|
+
if(other.contains(elem), {
|
|
101
|
+
result = result.insert(elem);
|
|
102
|
+
});
|
|
103
|
+
cur = cur.tail();
|
|
104
|
+
},
|
|
105
|
+
.None => {
|
|
106
|
+
done = true;
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
result
|
|
111
|
+
}),
|
|
112
|
+
|
|
113
|
+
/// Return the difference (`self \ other`).
|
|
114
|
+
difference : (fn(self: Self, other: Self) -> Self)({
|
|
115
|
+
elems := self.to_list();
|
|
116
|
+
(result : Self) = Self.new();
|
|
117
|
+
(cur : List(T)) = elems;
|
|
118
|
+
(done : bool) = false;
|
|
119
|
+
while runtime(!(done)), {
|
|
120
|
+
match(cur.head(),
|
|
121
|
+
.Some(elem) => {
|
|
122
|
+
if(!(other.contains(elem)), {
|
|
123
|
+
result = result.insert(elem);
|
|
124
|
+
});
|
|
125
|
+
cur = cur.tail();
|
|
126
|
+
},
|
|
127
|
+
.None => {
|
|
128
|
+
done = true;
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
result
|
|
133
|
+
}),
|
|
134
|
+
|
|
135
|
+
/// Check if `self` is a subset of `other`.
|
|
136
|
+
is_subset : (fn(self: Self, other: Self) -> bool)({
|
|
137
|
+
if((self.len() > other.len()), {
|
|
138
|
+
return false;
|
|
139
|
+
});
|
|
140
|
+
elems := self.to_list();
|
|
141
|
+
(cur : List(T)) = elems;
|
|
142
|
+
(result : bool) = true;
|
|
143
|
+
while runtime((result && !(cur.is_empty()))), {
|
|
144
|
+
match(cur.head(),
|
|
145
|
+
.Some(elem) => {
|
|
146
|
+
if(!(other.contains(elem)), {
|
|
147
|
+
result = false;
|
|
148
|
+
});
|
|
149
|
+
cur = cur.tail();
|
|
150
|
+
},
|
|
151
|
+
.None => ()
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
result
|
|
155
|
+
}),
|
|
156
|
+
|
|
157
|
+
/// Check if two sorted sets are disjoint.
|
|
158
|
+
is_disjoint : (fn(self: Self, other: Self) -> bool)({
|
|
159
|
+
(smaller : Self) = cond(
|
|
160
|
+
(self.len() <= other.len()) => self,
|
|
161
|
+
true => other
|
|
162
|
+
);
|
|
163
|
+
(larger : Self) = cond(
|
|
164
|
+
(self.len() <= other.len()) => other,
|
|
165
|
+
true => self
|
|
166
|
+
);
|
|
167
|
+
elems := smaller.to_list();
|
|
168
|
+
(cur : List(T)) = elems;
|
|
169
|
+
(result : bool) = true;
|
|
170
|
+
while runtime((result && !(cur.is_empty()))), {
|
|
171
|
+
match(cur.head(),
|
|
172
|
+
.Some(elem) => {
|
|
173
|
+
if(larger.contains(elem), {
|
|
174
|
+
result = false;
|
|
175
|
+
});
|
|
176
|
+
cur = cur.tail();
|
|
177
|
+
},
|
|
178
|
+
.None => ()
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
result
|
|
182
|
+
}),
|
|
183
|
+
|
|
184
|
+
/// Create a sorted set from a slice of elements.
|
|
185
|
+
from_slice : (fn(s: Slice(T)) -> Self)({
|
|
186
|
+
(result : Self) = Self.new();
|
|
187
|
+
i := usize(0);
|
|
188
|
+
slen := s.len();
|
|
189
|
+
while (i < slen), (i = (i + usize(1))), {
|
|
190
|
+
result = result.insert((s.ptr() &+ i).*);
|
|
191
|
+
};
|
|
192
|
+
result
|
|
193
|
+
})
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
impl(forall(T : Type), where(T <: (Eq(T), Ord(T), Send)), SortedSet(T), Eq(SortedSet(T))(
|
|
197
|
+
(==) : (fn(lhs: Self, rhs: Self) -> bool)(
|
|
198
|
+
(lhs._inner == rhs._inner)
|
|
199
|
+
)
|
|
200
|
+
));
|
|
201
|
+
|
|
202
|
+
export SortedSet;
|