@quenty/observablecollection 12.11.1 → 12.12.0
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/CHANGELOG.md +27 -0
- package/package.json +10 -9
- package/src/Shared/ObservableCountingMap.lua +9 -0
- package/src/Shared/ObservableList.lua +37 -28
- package/src/Shared/ObservableMap.lua +10 -0
- package/src/Shared/ObservableSet.lua +9 -0
- package/src/Shared/SortedList/ObservableSortedList.lua +586 -0
- package/src/Shared/{ObservableSortedList.story.lua → SortedList/ObservableSortedList.story.lua} +15 -12
- package/src/Shared/{ObservableSortedList.lua → SortedList/ObservableSortedListOld.lua} +37 -74
- package/src/Shared/SortedList/ObservableSortedList_Performance.story.lua +74 -0
- package/src/Shared/SortedList/ObservableSortedList_Print.story.lua +65 -0
- package/src/Shared/SortedList/SortFunctionUtils.lua +31 -0
- package/src/Shared/SortedList/SortedNode.lua +1171 -0
- package/src/Shared/SortedList/SortedNodeValue.lua +53 -0
- package/src/Shared/Utils/ListIndexUtils.lua +39 -0
- package/test/default.project.json +1 -7
- /package/src/Shared/{ObservableSortedList.spec.lua → SortedList/ObservableSortedList.spec.lua} +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
Simplifies comparison logic
|
|
3
|
+
|
|
4
|
+
@class SortedNodeValue
|
|
5
|
+
]=]
|
|
6
|
+
|
|
7
|
+
local require = require(script.Parent.loader).load(script)
|
|
8
|
+
|
|
9
|
+
local DuckTypeUtils = require("DuckTypeUtils")
|
|
10
|
+
|
|
11
|
+
local SortedNodeValue = {}
|
|
12
|
+
SortedNodeValue.ClassName = "SortedNodeValue"
|
|
13
|
+
SortedNodeValue.__index = SortedNodeValue
|
|
14
|
+
|
|
15
|
+
function SortedNodeValue.new(value, compare)
|
|
16
|
+
local self = setmetatable({}, SortedNodeValue)
|
|
17
|
+
|
|
18
|
+
self._value = value
|
|
19
|
+
self._compare = compare
|
|
20
|
+
|
|
21
|
+
return self
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
function SortedNodeValue:GetValue()
|
|
25
|
+
return self._value
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
function SortedNodeValue.isSortedNodeValue(value)
|
|
29
|
+
return DuckTypeUtils.isImplementation(SortedNodeValue, value)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
function SortedNodeValue:__eq(other)
|
|
33
|
+
assert(SortedNodeValue.isSortedNodeValue(other), "Bad other")
|
|
34
|
+
assert(other._compare == self._compare, "Bad compare")
|
|
35
|
+
|
|
36
|
+
return self._compare(self._value, other._value) == 0
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
function SortedNodeValue:__lt(other)
|
|
40
|
+
assert(SortedNodeValue.isSortedNodeValue(other), "Bad other")
|
|
41
|
+
assert(other._compare == self._compare, "Bad compare")
|
|
42
|
+
|
|
43
|
+
return self._compare(self._value, other._value) < 0
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
function SortedNodeValue:__gt(other)
|
|
47
|
+
assert(SortedNodeValue.isSortedNodeValue(other), "Bad other")
|
|
48
|
+
assert(other._compare == self._compare, "Bad compare")
|
|
49
|
+
|
|
50
|
+
return self._compare(self._value, other._value) > 0
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
return SortedNodeValue
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
@class ListIndexUtils
|
|
3
|
+
]=]
|
|
4
|
+
|
|
5
|
+
local require = require(script.Parent.loader).load(script)
|
|
6
|
+
|
|
7
|
+
local ListIndexUtils = {}
|
|
8
|
+
|
|
9
|
+
--[=[
|
|
10
|
+
Converts a negative index to a positive one for the list indexing
|
|
11
|
+
]=]
|
|
12
|
+
function ListIndexUtils.toPositiveIndex(listLength: number, index: number): number
|
|
13
|
+
assert(type(listLength) == "number", "Bad listLength")
|
|
14
|
+
assert(type(index) == "number", "Bad index")
|
|
15
|
+
|
|
16
|
+
if index > 0 then
|
|
17
|
+
return index
|
|
18
|
+
elseif index < 0 then
|
|
19
|
+
return listLength + index + 1
|
|
20
|
+
else
|
|
21
|
+
error(string.format("[ListIndexUtils.toPositiveIndex] - Bad index %d", index))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
--[=[
|
|
26
|
+
Converts a positive index to a negative one for list indexing
|
|
27
|
+
]=]
|
|
28
|
+
function ListIndexUtils.toNegativeIndex(listLength: number, index: number): number
|
|
29
|
+
assert(type(listLength) == "number", "Bad listLength")
|
|
30
|
+
assert(type(index) == "number", "Bad index")
|
|
31
|
+
|
|
32
|
+
if index <= 0 then
|
|
33
|
+
error(string.format("[ListIndexUtils.toPositiveIndex] - Invalid positive index %d", index))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
return -listLength + index - 1
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
return ListIndexUtils
|
|
@@ -4,13 +4,7 @@
|
|
|
4
4
|
"$className": "DataModel",
|
|
5
5
|
"ServerScriptService": {
|
|
6
6
|
"observablecollection": {
|
|
7
|
-
"$
|
|
8
|
-
"observablecollection": {
|
|
9
|
-
"$path": ".."
|
|
10
|
-
},
|
|
11
|
-
"instanceutils": {
|
|
12
|
-
"$path": "../../instanceutils"
|
|
13
|
-
}
|
|
7
|
+
"$path": ".."
|
|
14
8
|
},
|
|
15
9
|
"Script": {
|
|
16
10
|
"$path": "scripts/Server"
|
/package/src/Shared/{ObservableSortedList.spec.lua → SortedList/ObservableSortedList.spec.lua}
RENAMED
|
File without changes
|