@editframe/elements 0.30.2-beta.0 → 0.31.0-beta.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/dist/EF_FRAMEGEN.d.ts +5 -0
- package/dist/EF_FRAMEGEN.js +20 -4
- package/dist/EF_FRAMEGEN.js.map +1 -1
- package/dist/EF_INTERACTIVE.js.map +1 -1
- package/dist/_virtual/rolldown_runtime.js +27 -0
- package/dist/canvas/EFCanvas.d.ts +311 -0
- package/dist/canvas/EFCanvas.js +1089 -0
- package/dist/canvas/EFCanvas.js.map +1 -0
- package/dist/canvas/EFCanvasItem.d.ts +55 -0
- package/dist/canvas/EFCanvasItem.js +72 -0
- package/dist/canvas/EFCanvasItem.js.map +1 -0
- package/dist/canvas/api/CanvasAPI.d.ts +115 -0
- package/dist/canvas/api/CanvasAPI.js +182 -0
- package/dist/canvas/api/CanvasAPI.js.map +1 -0
- package/dist/canvas/api/types.d.ts +42 -0
- package/dist/canvas/coordinateTransform.js +90 -0
- package/dist/canvas/coordinateTransform.js.map +1 -0
- package/dist/canvas/getElementBounds.js +40 -0
- package/dist/canvas/getElementBounds.js.map +1 -0
- package/dist/canvas/overlays/SelectionOverlay.js +265 -0
- package/dist/canvas/overlays/SelectionOverlay.js.map +1 -0
- package/dist/canvas/overlays/overlayState.js +153 -0
- package/dist/canvas/overlays/overlayState.js.map +1 -0
- package/dist/canvas/selection/SelectionController.js +105 -0
- package/dist/canvas/selection/SelectionController.js.map +1 -0
- package/dist/canvas/selection/SelectionModel.d.ts +98 -0
- package/dist/canvas/selection/SelectionModel.js +229 -0
- package/dist/canvas/selection/SelectionModel.js.map +1 -0
- package/dist/canvas/selection/selectionContext.d.ts +31 -0
- package/dist/canvas/selection/selectionContext.js +12 -0
- package/dist/canvas/selection/selectionContext.js.map +1 -0
- package/dist/elements/ContainerInfo.d.ts +29 -0
- package/dist/elements/ContainerInfo.js +30 -0
- package/dist/elements/ContainerInfo.js.map +1 -0
- package/dist/elements/EFAudio.d.ts +13 -3
- package/dist/elements/EFAudio.js +64 -10
- package/dist/elements/EFAudio.js.map +1 -1
- package/dist/elements/EFCaptions.d.ts +18 -16
- package/dist/elements/EFCaptions.js +110 -19
- package/dist/elements/EFCaptions.js.map +1 -1
- package/dist/elements/EFImage.d.ts +12 -2
- package/dist/elements/EFImage.js +79 -9
- package/dist/elements/EFImage.js.map +1 -1
- package/dist/elements/EFMedia/AssetIdMediaEngine.js +51 -4
- package/dist/elements/EFMedia/AssetIdMediaEngine.js.map +1 -1
- package/dist/elements/EFMedia/AssetMediaEngine.js +125 -52
- package/dist/elements/EFMedia/AssetMediaEngine.js.map +1 -1
- package/dist/elements/EFMedia/BaseMediaEngine.js +24 -6
- package/dist/elements/EFMedia/BaseMediaEngine.js.map +1 -1
- package/dist/elements/EFMedia/JitMediaEngine.js +12 -8
- package/dist/elements/EFMedia/JitMediaEngine.js.map +1 -1
- package/dist/elements/EFMedia/audioTasks/makeAudioBufferTask.js +46 -7
- package/dist/elements/EFMedia/audioTasks/makeAudioBufferTask.js.map +1 -1
- package/dist/elements/EFMedia/audioTasks/makeAudioFrequencyAnalysisTask.js +98 -73
- package/dist/elements/EFMedia/audioTasks/makeAudioFrequencyAnalysisTask.js.map +1 -1
- package/dist/elements/EFMedia/audioTasks/makeAudioInitSegmentFetchTask.js +28 -5
- package/dist/elements/EFMedia/audioTasks/makeAudioInitSegmentFetchTask.js.map +1 -1
- package/dist/elements/EFMedia/audioTasks/makeAudioInputTask.js +18 -6
- package/dist/elements/EFMedia/audioTasks/makeAudioInputTask.js.map +1 -1
- package/dist/elements/EFMedia/audioTasks/makeAudioSeekTask.js +8 -2
- package/dist/elements/EFMedia/audioTasks/makeAudioSeekTask.js.map +1 -1
- package/dist/elements/EFMedia/audioTasks/makeAudioSegmentFetchTask.js +31 -6
- package/dist/elements/EFMedia/audioTasks/makeAudioSegmentFetchTask.js.map +1 -1
- package/dist/elements/EFMedia/audioTasks/makeAudioSegmentIdTask.js +28 -5
- package/dist/elements/EFMedia/audioTasks/makeAudioSegmentIdTask.js.map +1 -1
- package/dist/elements/EFMedia/audioTasks/makeAudioTimeDomainAnalysisTask.js +97 -72
- package/dist/elements/EFMedia/audioTasks/makeAudioTimeDomainAnalysisTask.js.map +1 -1
- package/dist/elements/EFMedia/shared/AudioSpanUtils.js +3 -1
- package/dist/elements/EFMedia/shared/AudioSpanUtils.js.map +1 -1
- package/dist/elements/EFMedia/shared/BufferUtils.js +1 -1
- package/dist/elements/EFMedia/shared/BufferUtils.js.map +1 -1
- package/dist/elements/EFMedia/shared/ThumbnailExtractor.js +25 -14
- package/dist/elements/EFMedia/shared/ThumbnailExtractor.js.map +1 -1
- package/dist/elements/EFMedia/tasks/makeMediaEngineTask.js +47 -16
- package/dist/elements/EFMedia/tasks/makeMediaEngineTask.js.map +1 -1
- package/dist/elements/EFMedia/videoTasks/MainVideoInputCache.js +37 -19
- package/dist/elements/EFMedia/videoTasks/MainVideoInputCache.js.map +1 -1
- package/dist/elements/EFMedia/videoTasks/ScrubInputCache.js +65 -21
- package/dist/elements/EFMedia/videoTasks/ScrubInputCache.js.map +1 -1
- package/dist/elements/EFMedia/videoTasks/makeScrubVideoBufferTask.js +8 -3
- package/dist/elements/EFMedia/videoTasks/makeScrubVideoBufferTask.js.map +1 -1
- package/dist/elements/EFMedia/videoTasks/makeScrubVideoInitSegmentFetchTask.js +32 -9
- package/dist/elements/EFMedia/videoTasks/makeScrubVideoInitSegmentFetchTask.js.map +1 -1
- package/dist/elements/EFMedia/videoTasks/makeScrubVideoInputTask.js +33 -10
- package/dist/elements/EFMedia/videoTasks/makeScrubVideoInputTask.js.map +1 -1
- package/dist/elements/EFMedia/videoTasks/makeScrubVideoSeekTask.js +23 -8
- package/dist/elements/EFMedia/videoTasks/makeScrubVideoSeekTask.js.map +1 -1
- package/dist/elements/EFMedia/videoTasks/makeScrubVideoSegmentFetchTask.js +34 -10
- package/dist/elements/EFMedia/videoTasks/makeScrubVideoSegmentFetchTask.js.map +1 -1
- package/dist/elements/EFMedia/videoTasks/makeScrubVideoSegmentIdTask.js +31 -8
- package/dist/elements/EFMedia/videoTasks/makeScrubVideoSegmentIdTask.js.map +1 -1
- package/dist/elements/EFMedia/videoTasks/makeUnifiedVideoSeekTask.js +31 -114
- package/dist/elements/EFMedia/videoTasks/makeUnifiedVideoSeekTask.js.map +1 -1
- package/dist/elements/EFMedia/videoTasks/makeVideoBufferTask.js +44 -8
- package/dist/elements/EFMedia/videoTasks/makeVideoBufferTask.js.map +1 -1
- package/dist/elements/EFMedia.d.ts +18 -7
- package/dist/elements/EFMedia.js +23 -3
- package/dist/elements/EFMedia.js.map +1 -1
- package/dist/elements/EFPanZoom.d.ts +96 -0
- package/dist/elements/EFPanZoom.js +290 -0
- package/dist/elements/EFPanZoom.js.map +1 -0
- package/dist/elements/EFSourceMixin.js +7 -6
- package/dist/elements/EFSourceMixin.js.map +1 -1
- package/dist/elements/EFSurface.d.ts +6 -6
- package/dist/elements/EFSurface.js +7 -2
- package/dist/elements/EFSurface.js.map +1 -1
- package/dist/elements/EFTemporal.d.ts +2 -1
- package/dist/elements/EFTemporal.js +192 -71
- package/dist/elements/EFTemporal.js.map +1 -1
- package/dist/elements/EFText.d.ts +5 -4
- package/dist/elements/EFText.js +102 -13
- package/dist/elements/EFText.js.map +1 -1
- package/dist/elements/EFTextSegment.d.ts +32 -6
- package/dist/elements/EFTextSegment.js +53 -15
- package/dist/elements/EFTextSegment.js.map +1 -1
- package/dist/elements/EFThumbnailStrip.d.ts +118 -56
- package/dist/elements/EFThumbnailStrip.js +522 -358
- package/dist/elements/EFThumbnailStrip.js.map +1 -1
- package/dist/elements/EFTimegroup.d.ts +223 -27
- package/dist/elements/EFTimegroup.js +850 -147
- package/dist/elements/EFTimegroup.js.map +1 -1
- package/dist/elements/EFVideo.d.ts +42 -5
- package/dist/elements/EFVideo.js +165 -11
- package/dist/elements/EFVideo.js.map +1 -1
- package/dist/elements/EFWaveform.d.ts +6 -6
- package/dist/elements/EFWaveform.js +2 -1
- package/dist/elements/EFWaveform.js.map +1 -1
- package/dist/elements/ElementPositionInfo.d.ts +35 -0
- package/dist/elements/ElementPositionInfo.js +49 -0
- package/dist/elements/ElementPositionInfo.js.map +1 -0
- package/dist/elements/FetchMixin.js +16 -1
- package/dist/elements/FetchMixin.js.map +1 -1
- package/dist/elements/SessionThumbnailCache.js +152 -0
- package/dist/elements/SessionThumbnailCache.js.map +1 -0
- package/dist/elements/TargetController.js +3 -1
- package/dist/elements/TargetController.js.map +1 -1
- package/dist/elements/TimegroupController.js +9 -3
- package/dist/elements/TimegroupController.js.map +1 -1
- package/dist/elements/findRootTemporal.js +30 -0
- package/dist/elements/findRootTemporal.js.map +1 -0
- package/dist/elements/renderTemporalAudio.js +18 -5
- package/dist/elements/renderTemporalAudio.js.map +1 -1
- package/dist/elements/updateAnimations.js +171 -28
- package/dist/elements/updateAnimations.js.map +1 -1
- package/dist/getRenderInfo.d.ts +2 -2
- package/dist/gui/ContextMixin.js +4 -2
- package/dist/gui/ContextMixin.js.map +1 -1
- package/dist/gui/Controllable.js +74 -1
- package/dist/gui/Controllable.js.map +1 -1
- package/dist/gui/EFActiveRootTemporal.d.ts +50 -0
- package/dist/gui/EFActiveRootTemporal.js +94 -0
- package/dist/gui/EFActiveRootTemporal.js.map +1 -0
- package/dist/gui/EFConfiguration.d.ts +11 -5
- package/dist/gui/EFConfiguration.js.map +1 -1
- package/dist/gui/EFControls.d.ts +2 -2
- package/dist/gui/EFControls.js +109 -13
- package/dist/gui/EFControls.js.map +1 -1
- package/dist/gui/EFDial.d.ts +4 -4
- package/dist/gui/EFFilmstrip.d.ts +11 -214
- package/dist/gui/EFFilmstrip.js +53 -1152
- package/dist/gui/EFFilmstrip.js.map +1 -1
- package/dist/gui/EFFitScale.d.ts +3 -3
- package/dist/gui/EFFitScale.js +39 -12
- package/dist/gui/EFFitScale.js.map +1 -1
- package/dist/gui/EFFocusOverlay.d.ts +4 -4
- package/dist/gui/EFOverlayItem.d.ts +48 -0
- package/dist/gui/EFOverlayItem.js +97 -0
- package/dist/gui/EFOverlayItem.js.map +1 -0
- package/dist/gui/EFOverlayLayer.d.ts +70 -0
- package/dist/gui/EFOverlayLayer.js +104 -0
- package/dist/gui/EFOverlayLayer.js.map +1 -0
- package/dist/gui/EFPause.d.ts +4 -4
- package/dist/gui/EFPlay.d.ts +4 -4
- package/dist/gui/EFResizableBox.d.ts +12 -16
- package/dist/gui/EFResizableBox.js +109 -451
- package/dist/gui/EFResizableBox.js.map +1 -1
- package/dist/gui/EFScrubber.d.ts +30 -5
- package/dist/gui/EFScrubber.js +224 -31
- package/dist/gui/EFScrubber.js.map +1 -1
- package/dist/gui/EFTimeDisplay.d.ts +4 -4
- package/dist/gui/EFTimeDisplay.js +4 -1
- package/dist/gui/EFTimeDisplay.js.map +1 -1
- package/dist/gui/EFTimelineRuler.d.ts +71 -0
- package/dist/gui/EFTimelineRuler.js +320 -0
- package/dist/gui/EFTimelineRuler.js.map +1 -0
- package/dist/gui/EFToggleLoop.d.ts +4 -4
- package/dist/gui/EFTogglePlay.d.ts +4 -4
- package/dist/gui/EFTransformHandles.d.ts +91 -0
- package/dist/gui/EFTransformHandles.js +393 -0
- package/dist/gui/EFTransformHandles.js.map +1 -0
- package/dist/gui/EFWorkbench.d.ts +182 -4
- package/dist/gui/EFWorkbench.js +2067 -22
- package/dist/gui/EFWorkbench.js.map +1 -1
- package/dist/gui/FitScaleHelpers.d.ts +31 -0
- package/dist/gui/FitScaleHelpers.js +41 -0
- package/dist/gui/FitScaleHelpers.js.map +1 -0
- package/dist/gui/PlaybackController.d.ts +2 -1
- package/dist/gui/PlaybackController.js +46 -15
- package/dist/gui/PlaybackController.js.map +1 -1
- package/dist/gui/TWMixin.js +1 -1
- package/dist/gui/TWMixin.js.map +1 -1
- package/dist/gui/hierarchy/EFHierarchy.d.ts +65 -0
- package/dist/gui/hierarchy/EFHierarchy.js +338 -0
- package/dist/gui/hierarchy/EFHierarchy.js.map +1 -0
- package/dist/gui/hierarchy/EFHierarchyItem.d.ts +118 -0
- package/dist/gui/hierarchy/EFHierarchyItem.js +551 -0
- package/dist/gui/hierarchy/EFHierarchyItem.js.map +1 -0
- package/dist/gui/hierarchy/hierarchyContext.d.ts +38 -0
- package/dist/gui/hierarchy/hierarchyContext.js +8 -0
- package/dist/gui/hierarchy/hierarchyContext.js.map +1 -0
- package/dist/gui/icons.js +34 -0
- package/dist/gui/icons.js.map +1 -0
- package/dist/gui/panZoomTransformContext.js +12 -0
- package/dist/gui/panZoomTransformContext.js.map +1 -0
- package/dist/gui/previewSettingsContext.js +12 -0
- package/dist/gui/previewSettingsContext.js.map +1 -0
- package/dist/gui/timeline/EFTimeline.d.ts +270 -0
- package/dist/gui/timeline/EFTimeline.js +1369 -0
- package/dist/gui/timeline/EFTimeline.js.map +1 -0
- package/dist/gui/timeline/EFTimelineRow.js +374 -0
- package/dist/gui/timeline/EFTimelineRow.js.map +1 -0
- package/dist/gui/timeline/TrimHandles.d.ts +36 -0
- package/dist/gui/timeline/TrimHandles.js +204 -0
- package/dist/gui/timeline/TrimHandles.js.map +1 -0
- package/dist/gui/timeline/flattenHierarchy.js +31 -0
- package/dist/gui/timeline/flattenHierarchy.js.map +1 -0
- package/dist/gui/timeline/timelineStateContext.d.ts +26 -0
- package/dist/gui/timeline/timelineStateContext.js +42 -0
- package/dist/gui/timeline/timelineStateContext.js.map +1 -0
- package/dist/gui/timeline/tracks/AudioTrack.js +264 -0
- package/dist/gui/timeline/tracks/AudioTrack.js.map +1 -0
- package/dist/gui/timeline/tracks/CaptionsTrack.js +595 -0
- package/dist/gui/timeline/tracks/CaptionsTrack.js.map +1 -0
- package/dist/gui/timeline/tracks/HTMLTrack.js +19 -0
- package/dist/gui/timeline/tracks/HTMLTrack.js.map +1 -0
- package/dist/gui/timeline/tracks/ImageTrack.js +53 -0
- package/dist/gui/timeline/tracks/ImageTrack.js.map +1 -0
- package/dist/gui/timeline/tracks/TextTrack.js +250 -0
- package/dist/gui/timeline/tracks/TextTrack.js.map +1 -0
- package/dist/gui/timeline/tracks/TimegroupTrack.js +143 -0
- package/dist/gui/timeline/tracks/TimegroupTrack.js.map +1 -0
- package/dist/gui/timeline/tracks/TrackItem.js +269 -0
- package/dist/gui/timeline/tracks/TrackItem.js.map +1 -0
- package/dist/gui/timeline/tracks/VideoTrack.js +265 -0
- package/dist/gui/timeline/tracks/VideoTrack.js.map +1 -0
- package/dist/gui/timeline/tracks/WaveformTrack.js +19 -0
- package/dist/gui/timeline/tracks/WaveformTrack.js.map +1 -0
- package/dist/gui/timeline/tracks/ensureTrackItemInit.js +1 -0
- package/dist/gui/timeline/tracks/preloadTracks.js +9 -0
- package/dist/gui/timeline/tracks/renderTrackChildren.js +119 -0
- package/dist/gui/timeline/tracks/renderTrackChildren.js.map +1 -0
- package/dist/gui/timeline/tracks/waveformUtils.js +80 -0
- package/dist/gui/timeline/tracks/waveformUtils.js.map +1 -0
- package/dist/gui/transformCalculations.js +217 -0
- package/dist/gui/transformCalculations.js.map +1 -0
- package/dist/gui/transformUtils.d.ts +37 -0
- package/dist/gui/transformUtils.js +77 -0
- package/dist/gui/transformUtils.js.map +1 -0
- package/dist/gui/tree/EFTree.d.ts +59 -0
- package/dist/gui/tree/EFTree.js +174 -0
- package/dist/gui/tree/EFTree.js.map +1 -0
- package/dist/gui/tree/EFTreeItem.d.ts +38 -0
- package/dist/gui/tree/EFTreeItem.js +146 -0
- package/dist/gui/tree/EFTreeItem.js.map +1 -0
- package/dist/gui/tree/treeContext.d.ts +60 -0
- package/dist/gui/tree/treeContext.js +23 -0
- package/dist/gui/tree/treeContext.js.map +1 -0
- package/dist/index.d.ts +32 -8
- package/dist/index.js +30 -6
- package/dist/index.js.map +1 -1
- package/dist/node_modules/react/cjs/react-jsx-runtime.development.js +688 -0
- package/dist/node_modules/react/cjs/react-jsx-runtime.development.js.map +1 -0
- package/dist/node_modules/react/cjs/react.development.js +1521 -0
- package/dist/node_modules/react/cjs/react.development.js.map +1 -0
- package/dist/node_modules/react/index.js +13 -0
- package/dist/node_modules/react/index.js.map +1 -0
- package/dist/node_modules/react/jsx-runtime.js +13 -0
- package/dist/node_modules/react/jsx-runtime.js.map +1 -0
- package/dist/preview/AdaptiveResolutionTracker.js +228 -0
- package/dist/preview/AdaptiveResolutionTracker.js.map +1 -0
- package/dist/preview/RenderProfiler.js +135 -0
- package/dist/preview/RenderProfiler.js.map +1 -0
- package/dist/preview/previewSettings.js +131 -0
- package/dist/preview/previewSettings.js.map +1 -0
- package/dist/preview/previewTypes.js +64 -0
- package/dist/preview/previewTypes.js.map +1 -0
- package/dist/preview/renderTimegroupPreview.js +656 -0
- package/dist/preview/renderTimegroupPreview.js.map +1 -0
- package/dist/preview/renderTimegroupToCanvas.d.ts +37 -0
- package/dist/preview/renderTimegroupToCanvas.js +840 -0
- package/dist/preview/renderTimegroupToCanvas.js.map +1 -0
- package/dist/preview/renderTimegroupToVideo.d.ts +39 -0
- package/dist/preview/renderTimegroupToVideo.js +274 -0
- package/dist/preview/renderTimegroupToVideo.js.map +1 -0
- package/dist/preview/renderers.js +16 -0
- package/dist/preview/renderers.js.map +1 -0
- package/dist/preview/statsTrackingStrategy.js +201 -0
- package/dist/preview/statsTrackingStrategy.js.map +1 -0
- package/dist/preview/thumbnailCacheSettings.js +52 -0
- package/dist/preview/thumbnailCacheSettings.js.map +1 -0
- package/dist/preview/workers/WorkerPool.js +178 -0
- package/dist/preview/workers/WorkerPool.js.map +1 -0
- package/dist/sandbox/PlaybackControls.js +10 -0
- package/dist/sandbox/PlaybackControls.js.map +1 -0
- package/dist/sandbox/ScenarioRunner.js +1 -0
- package/dist/sandbox/index.js +2 -0
- package/dist/style.css +68 -67
- package/dist/transcoding/types/index.d.ts +2 -1
- package/dist/transcoding/utils/UrlGenerator.d.ts +6 -1
- package/dist/transcoding/utils/UrlGenerator.js +12 -3
- package/dist/transcoding/utils/UrlGenerator.js.map +1 -1
- package/dist/utils/LRUCache.js +1 -375
- package/dist/utils/LRUCache.js.map +1 -1
- package/dist/utils/frameTime.js +14 -0
- package/dist/utils/frameTime.js.map +1 -0
- package/package.json +3 -3
- package/test/profilingPlugin.ts +223 -0
- package/test/recordReplayProxyPlugin.js +22 -27
- package/test/thumbnail-performance-test.html +116 -0
- package/test/visualRegressionUtils.ts +286 -0
- package/types.json +1 -1
- package/dist/elements/TimegroupController.d.ts +0 -18
- package/dist/msToTimeCode.js +0 -17
- package/dist/msToTimeCode.js.map +0 -1
package/dist/utils/LRUCache.js
CHANGED
|
@@ -113,381 +113,7 @@ var SizeAwareLRUCache = class {
|
|
|
113
113
|
return this.maxSizeBytes;
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
|
-
/**
|
|
117
|
-
* Red-Black Tree node colors
|
|
118
|
-
*/
|
|
119
|
-
var Color = /* @__PURE__ */ function(Color$1) {
|
|
120
|
-
Color$1["RED"] = "RED";
|
|
121
|
-
Color$1["BLACK"] = "BLACK";
|
|
122
|
-
return Color$1;
|
|
123
|
-
}(Color || {});
|
|
124
|
-
/**
|
|
125
|
-
* Red-Black Tree node for ordered key storage
|
|
126
|
-
*/
|
|
127
|
-
var RBTreeNode = class {
|
|
128
|
-
constructor(key, color = Color.RED, left = null, right = null, parent = null) {
|
|
129
|
-
this.key = key;
|
|
130
|
-
this.color = color;
|
|
131
|
-
this.left = left;
|
|
132
|
-
this.right = right;
|
|
133
|
-
this.parent = parent;
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* Red-Black Tree implementation for O(log n) operations
|
|
138
|
-
* Supports insert, delete, search, range queries, and nearest neighbor
|
|
139
|
-
*/
|
|
140
|
-
var RedBlackTree = class {
|
|
141
|
-
constructor(compareFn) {
|
|
142
|
-
this.root = null;
|
|
143
|
-
this.compareFn = compareFn;
|
|
144
|
-
}
|
|
145
|
-
insert(key) {
|
|
146
|
-
const node = new RBTreeNode(key);
|
|
147
|
-
if (!this.root) {
|
|
148
|
-
this.root = node;
|
|
149
|
-
node.color = Color.BLACK;
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
this.insertNode(node);
|
|
153
|
-
this.fixInsert(node);
|
|
154
|
-
}
|
|
155
|
-
delete(key) {
|
|
156
|
-
const node = this.findNode(key);
|
|
157
|
-
if (!node) return false;
|
|
158
|
-
this.deleteNode(node);
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
find(key) {
|
|
162
|
-
const node = this.findNode(key);
|
|
163
|
-
return node ? node.key : null;
|
|
164
|
-
}
|
|
165
|
-
findNearestInRange(center, distance) {
|
|
166
|
-
const start = this.subtractDistance(center, distance);
|
|
167
|
-
const end = this.addDistance(center, distance);
|
|
168
|
-
return this.findRange(start, end);
|
|
169
|
-
}
|
|
170
|
-
subtractDistance(center, distance) {
|
|
171
|
-
if (typeof center === "number" && typeof distance === "number") return center - distance;
|
|
172
|
-
return center;
|
|
173
|
-
}
|
|
174
|
-
addDistance(center, distance) {
|
|
175
|
-
if (typeof center === "number" && typeof distance === "number") return center + distance;
|
|
176
|
-
return center;
|
|
177
|
-
}
|
|
178
|
-
findRange(start, end) {
|
|
179
|
-
const result = [];
|
|
180
|
-
this.inorderRange(this.root, start, end, result);
|
|
181
|
-
return result;
|
|
182
|
-
}
|
|
183
|
-
getAllSorted() {
|
|
184
|
-
const result = [];
|
|
185
|
-
this.inorder(this.root, result);
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
findNode(key) {
|
|
189
|
-
let current = this.root;
|
|
190
|
-
while (current) {
|
|
191
|
-
const cmp = this.compareFn(key, current.key);
|
|
192
|
-
if (cmp === 0) return current;
|
|
193
|
-
current = cmp < 0 ? current.left : current.right;
|
|
194
|
-
}
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
insertNode(node) {
|
|
198
|
-
let parent = null;
|
|
199
|
-
let current = this.root;
|
|
200
|
-
while (current) {
|
|
201
|
-
parent = current;
|
|
202
|
-
current = this.compareFn(node.key, current.key) < 0 ? current.left : current.right;
|
|
203
|
-
}
|
|
204
|
-
node.parent = parent;
|
|
205
|
-
if (!parent) this.root = node;
|
|
206
|
-
else if (this.compareFn(node.key, parent.key) < 0) parent.left = node;
|
|
207
|
-
else parent.right = node;
|
|
208
|
-
}
|
|
209
|
-
fixInsert(node) {
|
|
210
|
-
while (node.parent && node.parent.color === Color.RED) if (node.parent === node.parent.parent?.left) {
|
|
211
|
-
const uncle = node.parent.parent.right;
|
|
212
|
-
if (uncle?.color === Color.RED) {
|
|
213
|
-
node.parent.color = Color.BLACK;
|
|
214
|
-
uncle.color = Color.BLACK;
|
|
215
|
-
node.parent.parent.color = Color.RED;
|
|
216
|
-
node = node.parent.parent;
|
|
217
|
-
} else {
|
|
218
|
-
if (node === node.parent.right) {
|
|
219
|
-
node = node.parent;
|
|
220
|
-
this.rotateLeft(node);
|
|
221
|
-
}
|
|
222
|
-
if (node.parent) {
|
|
223
|
-
node.parent.color = Color.BLACK;
|
|
224
|
-
if (node.parent.parent) {
|
|
225
|
-
node.parent.parent.color = Color.RED;
|
|
226
|
-
this.rotateRight(node.parent.parent);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
} else {
|
|
231
|
-
const uncle = node.parent.parent?.left;
|
|
232
|
-
if (uncle?.color === Color.RED) {
|
|
233
|
-
node.parent.color = Color.BLACK;
|
|
234
|
-
uncle.color = Color.BLACK;
|
|
235
|
-
if (node.parent.parent) {
|
|
236
|
-
node.parent.parent.color = Color.RED;
|
|
237
|
-
node = node.parent.parent;
|
|
238
|
-
}
|
|
239
|
-
} else {
|
|
240
|
-
if (node === node.parent.left) {
|
|
241
|
-
node = node.parent;
|
|
242
|
-
this.rotateRight(node);
|
|
243
|
-
}
|
|
244
|
-
if (node.parent) {
|
|
245
|
-
node.parent.color = Color.BLACK;
|
|
246
|
-
if (node.parent.parent) {
|
|
247
|
-
node.parent.parent.color = Color.RED;
|
|
248
|
-
this.rotateLeft(node.parent.parent);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
if (this.root) this.root.color = Color.BLACK;
|
|
254
|
-
}
|
|
255
|
-
deleteNode(node) {
|
|
256
|
-
let y = node;
|
|
257
|
-
let yOriginalColor = y.color;
|
|
258
|
-
let x;
|
|
259
|
-
if (!node.left) {
|
|
260
|
-
x = node.right;
|
|
261
|
-
this.transplant(node, node.right);
|
|
262
|
-
} else if (!node.right) {
|
|
263
|
-
x = node.left;
|
|
264
|
-
this.transplant(node, node.left);
|
|
265
|
-
} else {
|
|
266
|
-
y = this.minimum(node.right);
|
|
267
|
-
yOriginalColor = y.color;
|
|
268
|
-
x = y.right;
|
|
269
|
-
if (y.parent === node) {
|
|
270
|
-
if (x) x.parent = y;
|
|
271
|
-
} else {
|
|
272
|
-
this.transplant(y, y.right);
|
|
273
|
-
y.right = node.right;
|
|
274
|
-
if (y.right) y.right.parent = y;
|
|
275
|
-
}
|
|
276
|
-
this.transplant(node, y);
|
|
277
|
-
y.left = node.left;
|
|
278
|
-
if (y.left) y.left.parent = y;
|
|
279
|
-
y.color = node.color;
|
|
280
|
-
}
|
|
281
|
-
if (yOriginalColor === Color.BLACK && x) this.fixDelete(x);
|
|
282
|
-
}
|
|
283
|
-
fixDelete(node) {
|
|
284
|
-
while (node !== this.root && node.color === Color.BLACK) if (node === node.parent?.left) {
|
|
285
|
-
let sibling = node.parent.right;
|
|
286
|
-
if (sibling?.color === Color.RED) {
|
|
287
|
-
sibling.color = Color.BLACK;
|
|
288
|
-
node.parent.color = Color.RED;
|
|
289
|
-
this.rotateLeft(node.parent);
|
|
290
|
-
sibling = node.parent.right;
|
|
291
|
-
}
|
|
292
|
-
if (sibling?.left?.color !== Color.RED && sibling?.right?.color !== Color.RED) {
|
|
293
|
-
if (sibling) sibling.color = Color.RED;
|
|
294
|
-
node = node.parent;
|
|
295
|
-
} else {
|
|
296
|
-
if (sibling?.right?.color !== Color.RED) {
|
|
297
|
-
if (sibling.left) sibling.left.color = Color.BLACK;
|
|
298
|
-
sibling.color = Color.RED;
|
|
299
|
-
this.rotateRight(sibling);
|
|
300
|
-
sibling = node.parent.right;
|
|
301
|
-
}
|
|
302
|
-
if (sibling) {
|
|
303
|
-
sibling.color = node.parent.color;
|
|
304
|
-
node.parent.color = Color.BLACK;
|
|
305
|
-
if (sibling.right) sibling.right.color = Color.BLACK;
|
|
306
|
-
this.rotateLeft(node.parent);
|
|
307
|
-
}
|
|
308
|
-
if (!this.root) throw new Error("Root is null");
|
|
309
|
-
node = this.root;
|
|
310
|
-
}
|
|
311
|
-
} else {
|
|
312
|
-
let sibling = node.parent?.left;
|
|
313
|
-
if (sibling?.color === Color.RED) {
|
|
314
|
-
sibling.color = Color.BLACK;
|
|
315
|
-
if (node.parent) node.parent.color = Color.RED;
|
|
316
|
-
if (node.parent) this.rotateRight(node.parent);
|
|
317
|
-
sibling = node.parent?.left;
|
|
318
|
-
}
|
|
319
|
-
if (sibling?.right?.color !== Color.RED && sibling?.left?.color !== Color.RED) {
|
|
320
|
-
if (sibling) sibling.color = Color.RED;
|
|
321
|
-
if (node.parent === null) throw new Error("Node parent is null");
|
|
322
|
-
node = node.parent;
|
|
323
|
-
} else {
|
|
324
|
-
if (sibling?.left?.color !== Color.RED) {
|
|
325
|
-
if (sibling.right) sibling.right.color = Color.BLACK;
|
|
326
|
-
sibling.color = Color.RED;
|
|
327
|
-
this.rotateLeft(sibling);
|
|
328
|
-
sibling = node.parent?.left;
|
|
329
|
-
}
|
|
330
|
-
if (sibling) {
|
|
331
|
-
sibling.color = node.parent?.color || Color.BLACK;
|
|
332
|
-
if (node.parent) node.parent.color = Color.BLACK;
|
|
333
|
-
if (sibling.left) sibling.left.color = Color.BLACK;
|
|
334
|
-
if (node.parent) this.rotateRight(node.parent);
|
|
335
|
-
}
|
|
336
|
-
if (!this.root) throw new Error("Root is null");
|
|
337
|
-
node = this.root;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
node.color = Color.BLACK;
|
|
341
|
-
}
|
|
342
|
-
rotateLeft(node) {
|
|
343
|
-
const rightChild = node.right;
|
|
344
|
-
if (!rightChild) throw new Error("Right child is null");
|
|
345
|
-
node.right = rightChild.left;
|
|
346
|
-
if (rightChild.left) rightChild.left.parent = node;
|
|
347
|
-
rightChild.parent = node.parent;
|
|
348
|
-
if (!node.parent) this.root = rightChild;
|
|
349
|
-
else if (node === node.parent.left) node.parent.left = rightChild;
|
|
350
|
-
else node.parent.right = rightChild;
|
|
351
|
-
rightChild.left = node;
|
|
352
|
-
node.parent = rightChild;
|
|
353
|
-
}
|
|
354
|
-
rotateRight(node) {
|
|
355
|
-
const leftChild = node.left;
|
|
356
|
-
if (!leftChild) throw new Error("Left child is null");
|
|
357
|
-
node.left = leftChild.right;
|
|
358
|
-
if (leftChild.right) leftChild.right.parent = node;
|
|
359
|
-
leftChild.parent = node.parent;
|
|
360
|
-
if (!node.parent) this.root = leftChild;
|
|
361
|
-
else if (node === node.parent.right) node.parent.right = leftChild;
|
|
362
|
-
else node.parent.left = leftChild;
|
|
363
|
-
leftChild.right = node;
|
|
364
|
-
node.parent = leftChild;
|
|
365
|
-
}
|
|
366
|
-
transplant(u, v) {
|
|
367
|
-
if (!u.parent) this.root = v;
|
|
368
|
-
else if (u === u.parent.left) u.parent.left = v;
|
|
369
|
-
else u.parent.right = v;
|
|
370
|
-
if (v) v.parent = u.parent;
|
|
371
|
-
}
|
|
372
|
-
minimum(node) {
|
|
373
|
-
while (node.left) node = node.left;
|
|
374
|
-
return node;
|
|
375
|
-
}
|
|
376
|
-
inorder(node, result) {
|
|
377
|
-
if (node) {
|
|
378
|
-
this.inorder(node.left, result);
|
|
379
|
-
result.push(node.key);
|
|
380
|
-
this.inorder(node.right, result);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
inorderRange(node, start, end, result) {
|
|
384
|
-
if (!node) return;
|
|
385
|
-
const startCmp = this.compareFn(node.key, start);
|
|
386
|
-
const endCmp = this.compareFn(node.key, end);
|
|
387
|
-
if (startCmp > 0) this.inorderRange(node.left, start, end, result);
|
|
388
|
-
if (startCmp >= 0 && endCmp <= 0) result.push(node.key);
|
|
389
|
-
if (endCmp < 0) this.inorderRange(node.right, start, end, result);
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
/**
|
|
393
|
-
* LRU cache with binary search capabilities using Red-Black tree
|
|
394
|
-
* All operations are O(log n) for ordered queries and O(1) for LRU operations
|
|
395
|
-
*/
|
|
396
|
-
var OrderedLRUCache = class {
|
|
397
|
-
constructor(maxSize, compareFn) {
|
|
398
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
399
|
-
this.maxSize = maxSize;
|
|
400
|
-
this.compareFn = compareFn || ((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
401
|
-
this.tree = new RedBlackTree(this.compareFn);
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* Get value by exact key (O(1))
|
|
405
|
-
*/
|
|
406
|
-
get(key) {
|
|
407
|
-
const value = this.cache.get(key);
|
|
408
|
-
if (value) {
|
|
409
|
-
this.cache.delete(key);
|
|
410
|
-
this.cache.set(key, value);
|
|
411
|
-
}
|
|
412
|
-
return value;
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Set key-value pair (O(log n) for tree operations, O(1) for cache)
|
|
416
|
-
*/
|
|
417
|
-
set(key, value) {
|
|
418
|
-
if (this.cache.has(key)) this.cache.delete(key);
|
|
419
|
-
else {
|
|
420
|
-
if (this.cache.size >= this.maxSize) {
|
|
421
|
-
const firstKey = this.cache.keys().next().value;
|
|
422
|
-
if (firstKey) {
|
|
423
|
-
this.cache.delete(firstKey);
|
|
424
|
-
this.tree.delete(firstKey);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
this.tree.insert(key);
|
|
428
|
-
}
|
|
429
|
-
this.cache.set(key, value);
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Find exact key using tree search (O(log n))
|
|
433
|
-
*/
|
|
434
|
-
findExact(key) {
|
|
435
|
-
if (this.tree.find(key) !== null) return this.get(key);
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Find keys within distance of center point (O(log n + k) where k is result count)
|
|
439
|
-
* Returns empty array if no keys found in range
|
|
440
|
-
*/
|
|
441
|
-
findNearestInRange(center, distance) {
|
|
442
|
-
const nearestKeys = this.tree.findNearestInRange(center, distance);
|
|
443
|
-
const result = [];
|
|
444
|
-
for (const key of nearestKeys) {
|
|
445
|
-
const value = this.get(key);
|
|
446
|
-
if (value !== void 0) result.push({
|
|
447
|
-
key,
|
|
448
|
-
value
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
return result;
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Find all key-value pairs in range [start, end] (O(log n + k) where k is result count)
|
|
455
|
-
*/
|
|
456
|
-
findRange(start, end) {
|
|
457
|
-
const keys = this.tree.findRange(start, end);
|
|
458
|
-
const result = [];
|
|
459
|
-
for (const key of keys) {
|
|
460
|
-
const value = this.get(key);
|
|
461
|
-
if (value !== void 0) result.push({
|
|
462
|
-
key,
|
|
463
|
-
value
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
return result;
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Get all keys in sorted order (O(n))
|
|
470
|
-
*/
|
|
471
|
-
getSortedKeys() {
|
|
472
|
-
return this.tree.getAllSorted();
|
|
473
|
-
}
|
|
474
|
-
has(key) {
|
|
475
|
-
return this.cache.has(key);
|
|
476
|
-
}
|
|
477
|
-
delete(key) {
|
|
478
|
-
const deleted = this.cache.delete(key);
|
|
479
|
-
if (deleted) this.tree.delete(key);
|
|
480
|
-
return deleted;
|
|
481
|
-
}
|
|
482
|
-
clear() {
|
|
483
|
-
this.cache.clear();
|
|
484
|
-
this.tree = new RedBlackTree(this.compareFn);
|
|
485
|
-
}
|
|
486
|
-
get size() {
|
|
487
|
-
return this.cache.size;
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
116
|
|
|
491
117
|
//#endregion
|
|
492
|
-
export { LRUCache,
|
|
118
|
+
export { LRUCache, SizeAwareLRUCache };
|
|
493
119
|
//# sourceMappingURL=LRUCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LRUCache.js","names":["key: K","color: Color","left: RBTreeNode<K> | null","right: RBTreeNode<K> | null","parent: RBTreeNode<K> | null","result: K[]","x: RBTreeNode<K> | null","result: Array<{ key: K; value: V }>"],"sources":["../../src/utils/LRUCache.ts"],"sourcesContent":["/**\n * A simple LRU (Least Recently Used) cache implementation\n */\nexport class LRUCache<K, V> {\n private cache = new Map<K, V>();\n private readonly maxSize: number;\n\n constructor(maxSize: number) {\n this.maxSize = maxSize;\n }\n\n get(key: K): V | undefined {\n const value = this.cache.get(key);\n if (value) {\n // Refresh position by removing and re-adding\n this.cache.delete(key);\n this.cache.set(key, value);\n }\n return value;\n }\n\n set(key: K, value: V): void {\n if (this.cache.has(key)) {\n this.cache.delete(key);\n } else if (this.cache.size >= this.maxSize) {\n // Remove oldest entry (first item in map)\n const firstKey = this.cache.keys().next().value;\n if (firstKey) {\n this.cache.delete(firstKey);\n }\n }\n this.cache.set(key, value);\n }\n\n has(key: K): boolean {\n return this.cache.has(key);\n }\n\n delete(key: K): boolean {\n return this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n get size(): number {\n return this.cache.size;\n }\n}\n\n/**\n * Size-aware LRU cache that tracks memory usage in bytes\n * Evicts entries when total size exceeds the maximum\n */\nexport class SizeAwareLRUCache<K> {\n private cache = new Map<K, Promise<ArrayBuffer>>();\n private sizes = new Map<K, number>();\n private currentSize = 0;\n private readonly maxSizeBytes: number;\n\n constructor(maxSizeBytes: number) {\n this.maxSizeBytes = maxSizeBytes;\n }\n\n get(key: K): Promise<ArrayBuffer> | undefined {\n const value = this.cache.get(key);\n if (value) {\n // Refresh position by removing and re-adding\n const size = this.sizes.get(key) || 0;\n this.cache.delete(key);\n this.cache.set(key, value);\n this.sizes.delete(key);\n this.sizes.set(key, size);\n }\n return value;\n }\n\n set(key: K, value: Promise<ArrayBuffer>): void {\n // If key already exists, remove it first\n if (this.cache.has(key)) {\n const oldSize = this.sizes.get(key) || 0;\n this.currentSize -= oldSize;\n this.cache.delete(key);\n this.sizes.delete(key);\n }\n\n // Track the size when the promise resolves\n const sizeTrackingPromise = value\n .then((buffer) => {\n const bufferSize = buffer.byteLength;\n this.sizes.set(key, bufferSize);\n this.currentSize += bufferSize;\n\n // Evict oldest entries if we exceed the size limit\n this.evictIfNecessary();\n\n return buffer;\n })\n .catch((error) => {\n // If the promise fails, clean up the entry\n this.cache.delete(key);\n this.sizes.delete(key);\n throw error;\n });\n\n this.cache.set(key, sizeTrackingPromise);\n }\n\n private evictIfNecessary(): void {\n while (this.currentSize > this.maxSizeBytes && this.cache.size > 0) {\n // Remove oldest entry (first item in map)\n const firstKey = this.cache.keys().next().value;\n if (firstKey) {\n const size = this.sizes.get(firstKey) || 0;\n this.currentSize -= size;\n this.cache.delete(firstKey);\n this.sizes.delete(firstKey);\n } else {\n break;\n }\n }\n }\n\n has(key: K): boolean {\n return this.cache.has(key);\n }\n\n delete(key: K): boolean {\n const size = this.sizes.get(key) || 0;\n this.currentSize -= size;\n this.sizes.delete(key);\n return this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n this.sizes.clear();\n this.currentSize = 0;\n }\n\n get size(): number {\n return this.cache.size;\n }\n\n get currentSizeBytes(): number {\n return this.currentSize;\n }\n\n get maxSize(): number {\n return this.maxSizeBytes;\n }\n}\n\n/**\n * Red-Black Tree node colors\n */\nenum Color {\n RED = \"RED\",\n BLACK = \"BLACK\",\n}\n\n/**\n * Red-Black Tree node for ordered key storage\n */\nclass RBTreeNode<K> {\n constructor(\n public key: K,\n public color: Color = Color.RED,\n public left: RBTreeNode<K> | null = null,\n public right: RBTreeNode<K> | null = null,\n public parent: RBTreeNode<K> | null = null,\n ) {}\n}\n\n/**\n * Red-Black Tree implementation for O(log n) operations\n * Supports insert, delete, search, range queries, and nearest neighbor\n */\nclass RedBlackTree<K> {\n private root: RBTreeNode<K> | null = null;\n private readonly compareFn: (a: K, b: K) => number;\n\n constructor(compareFn: (a: K, b: K) => number) {\n this.compareFn = compareFn;\n }\n\n insert(key: K): void {\n const node = new RBTreeNode(key);\n\n if (!this.root) {\n this.root = node;\n node.color = Color.BLACK;\n return;\n }\n\n this.insertNode(node);\n this.fixInsert(node);\n }\n\n delete(key: K): boolean {\n const node = this.findNode(key);\n if (!node) return false;\n\n this.deleteNode(node);\n return true;\n }\n\n find(key: K): K | null {\n const node = this.findNode(key);\n return node ? node.key : null;\n }\n\n findNearestInRange(center: K, distance: K): K[] {\n // Calculate the range bounds\n const start = this.subtractDistance(center, distance);\n const end = this.addDistance(center, distance);\n\n // Use existing range search (O(log n + k))\n return this.findRange(start, end);\n }\n\n private subtractDistance(center: K, distance: K): K {\n if (typeof center === \"number\" && typeof distance === \"number\") {\n return (center - distance) as K;\n }\n\n // For strings, we can't easily subtract distance, so just return center\n // This means string searches will be exact matches only\n return center;\n }\n\n private addDistance(center: K, distance: K): K {\n if (typeof center === \"number\" && typeof distance === \"number\") {\n return (center + distance) as K;\n }\n\n // For strings, we can't easily add distance, so just return center\n // This means string searches will be exact matches only\n return center;\n }\n\n findRange(start: K, end: K): K[] {\n const result: K[] = [];\n this.inorderRange(this.root, start, end, result);\n return result;\n }\n\n getAllSorted(): K[] {\n const result: K[] = [];\n this.inorder(this.root, result);\n return result;\n }\n\n private findNode(key: K): RBTreeNode<K> | null {\n let current = this.root;\n\n while (current) {\n const cmp = this.compareFn(key, current.key);\n if (cmp === 0) return current;\n current = cmp < 0 ? current.left : current.right;\n }\n\n return null;\n }\n\n private insertNode(node: RBTreeNode<K>): void {\n let parent = null;\n let current = this.root;\n\n while (current) {\n parent = current;\n const cmp = this.compareFn(node.key, current.key);\n current = cmp < 0 ? current.left : current.right;\n }\n\n node.parent = parent;\n if (!parent) {\n this.root = node;\n } else {\n const cmp = this.compareFn(node.key, parent.key);\n if (cmp < 0) {\n parent.left = node;\n } else {\n parent.right = node;\n }\n }\n }\n\n private fixInsert(node: RBTreeNode<K>): void {\n while (node.parent && node.parent.color === Color.RED) {\n if (node.parent === node.parent.parent?.left) {\n const uncle = node.parent.parent.right;\n\n if (uncle?.color === Color.RED) {\n node.parent.color = Color.BLACK;\n uncle.color = Color.BLACK;\n node.parent.parent.color = Color.RED;\n node = node.parent.parent;\n } else {\n if (node === node.parent.right) {\n node = node.parent;\n this.rotateLeft(node);\n }\n\n if (node.parent) {\n node.parent.color = Color.BLACK;\n if (node.parent.parent) {\n node.parent.parent.color = Color.RED;\n this.rotateRight(node.parent.parent);\n }\n }\n }\n } else {\n const uncle = node.parent.parent?.left;\n\n if (uncle?.color === Color.RED) {\n node.parent.color = Color.BLACK;\n uncle.color = Color.BLACK;\n if (node.parent.parent) {\n node.parent.parent.color = Color.RED;\n node = node.parent.parent;\n }\n } else {\n if (node === node.parent.left) {\n node = node.parent;\n this.rotateRight(node);\n }\n\n if (node.parent) {\n node.parent.color = Color.BLACK;\n if (node.parent.parent) {\n node.parent.parent.color = Color.RED;\n this.rotateLeft(node.parent.parent);\n }\n }\n }\n }\n }\n\n if (this.root) {\n this.root.color = Color.BLACK;\n }\n }\n\n private deleteNode(node: RBTreeNode<K>): void {\n let y = node;\n let yOriginalColor = y.color;\n let x: RBTreeNode<K> | null;\n\n if (!node.left) {\n x = node.right;\n this.transplant(node, node.right);\n } else if (!node.right) {\n x = node.left;\n this.transplant(node, node.left);\n } else {\n y = this.minimum(node.right);\n yOriginalColor = y.color;\n x = y.right;\n\n if (y.parent === node) {\n if (x) x.parent = y;\n } else {\n this.transplant(y, y.right);\n y.right = node.right;\n if (y.right) y.right.parent = y;\n }\n\n this.transplant(node, y);\n y.left = node.left;\n if (y.left) y.left.parent = y;\n y.color = node.color;\n }\n\n if (yOriginalColor === Color.BLACK && x) {\n this.fixDelete(x);\n }\n }\n\n private fixDelete(node: RBTreeNode<K>): void {\n while (node !== this.root && node.color === Color.BLACK) {\n if (node === node.parent?.left) {\n let sibling = node.parent.right;\n\n if (sibling?.color === Color.RED) {\n sibling.color = Color.BLACK;\n node.parent.color = Color.RED;\n this.rotateLeft(node.parent);\n sibling = node.parent.right;\n }\n\n if (\n sibling?.left?.color !== Color.RED &&\n sibling?.right?.color !== Color.RED\n ) {\n if (sibling) {\n sibling.color = Color.RED;\n }\n node = node.parent;\n } else {\n if (sibling?.right?.color !== Color.RED) {\n if (sibling.left) sibling.left.color = Color.BLACK;\n sibling.color = Color.RED;\n this.rotateRight(sibling);\n sibling = node.parent.right;\n }\n\n if (sibling) {\n sibling.color = node.parent.color;\n node.parent.color = Color.BLACK;\n if (sibling.right) sibling.right.color = Color.BLACK;\n this.rotateLeft(node.parent);\n }\n if (!this.root) {\n throw new Error(\"Root is null\");\n }\n node = this.root;\n }\n } else {\n let sibling = node.parent?.left;\n\n if (sibling?.color === Color.RED) {\n sibling.color = Color.BLACK;\n if (node.parent) node.parent.color = Color.RED;\n if (node.parent) this.rotateRight(node.parent);\n sibling = node.parent?.left;\n }\n\n if (\n sibling?.right?.color !== Color.RED &&\n sibling?.left?.color !== Color.RED\n ) {\n if (sibling) {\n sibling.color = Color.RED;\n }\n if (node.parent === null) {\n throw new Error(\"Node parent is null\");\n }\n node = node.parent;\n } else {\n if (sibling?.left?.color !== Color.RED) {\n if (sibling.right) sibling.right.color = Color.BLACK;\n sibling.color = Color.RED;\n this.rotateLeft(sibling);\n sibling = node.parent?.left;\n }\n\n if (sibling) {\n sibling.color = node.parent?.color || Color.BLACK;\n if (node.parent) node.parent.color = Color.BLACK;\n if (sibling.left) sibling.left.color = Color.BLACK;\n if (node.parent) this.rotateRight(node.parent);\n }\n if (!this.root) {\n throw new Error(\"Root is null\");\n }\n node = this.root;\n }\n }\n }\n\n node.color = Color.BLACK;\n }\n\n private rotateLeft(node: RBTreeNode<K>): void {\n const rightChild = node.right;\n if (!rightChild) {\n throw new Error(\"Right child is null\");\n }\n node.right = rightChild.left;\n\n if (rightChild.left) {\n rightChild.left.parent = node;\n }\n\n rightChild.parent = node.parent;\n\n if (!node.parent) {\n this.root = rightChild;\n } else if (node === node.parent.left) {\n node.parent.left = rightChild;\n } else {\n node.parent.right = rightChild;\n }\n\n rightChild.left = node;\n node.parent = rightChild;\n }\n\n private rotateRight(node: RBTreeNode<K>): void {\n const leftChild = node.left;\n if (!leftChild) {\n throw new Error(\"Left child is null\");\n }\n node.left = leftChild.right;\n\n if (leftChild.right) {\n leftChild.right.parent = node;\n }\n\n leftChild.parent = node.parent;\n\n if (!node.parent) {\n this.root = leftChild;\n } else if (node === node.parent.right) {\n node.parent.right = leftChild;\n } else {\n node.parent.left = leftChild;\n }\n\n leftChild.right = node;\n node.parent = leftChild;\n }\n\n private transplant(u: RBTreeNode<K>, v: RBTreeNode<K> | null): void {\n if (!u.parent) {\n this.root = v;\n } else if (u === u.parent.left) {\n u.parent.left = v;\n } else {\n u.parent.right = v;\n }\n\n if (v) {\n v.parent = u.parent;\n }\n }\n\n private minimum(node: RBTreeNode<K>): RBTreeNode<K> {\n while (node.left) {\n node = node.left;\n }\n return node;\n }\n\n private inorder(node: RBTreeNode<K> | null, result: K[]): void {\n if (node) {\n this.inorder(node.left, result);\n result.push(node.key);\n this.inorder(node.right, result);\n }\n }\n\n private inorderRange(\n node: RBTreeNode<K> | null,\n start: K,\n end: K,\n result: K[],\n ): void {\n if (!node) return;\n\n const startCmp = this.compareFn(node.key, start);\n const endCmp = this.compareFn(node.key, end);\n\n if (startCmp > 0) {\n this.inorderRange(node.left, start, end, result);\n }\n\n if (startCmp >= 0 && endCmp <= 0) {\n result.push(node.key);\n }\n\n if (endCmp < 0) {\n this.inorderRange(node.right, start, end, result);\n }\n }\n}\n\n/**\n * LRU cache with binary search capabilities using Red-Black tree\n * All operations are O(log n) for ordered queries and O(1) for LRU operations\n */\nexport class OrderedLRUCache<K extends number | string, V> {\n private cache = new Map<K, V>();\n private tree: RedBlackTree<K>;\n private readonly maxSize: number;\n private readonly compareFn: (a: K, b: K) => number;\n\n constructor(maxSize: number, compareFn?: (a: K, b: K) => number) {\n this.maxSize = maxSize;\n this.compareFn = compareFn || ((a, b) => (a < b ? -1 : a > b ? 1 : 0));\n this.tree = new RedBlackTree(this.compareFn);\n }\n\n /**\n * Get value by exact key (O(1))\n */\n get(key: K): V | undefined {\n const value = this.cache.get(key);\n if (value) {\n // Refresh position by removing and re-adding\n this.cache.delete(key);\n this.cache.set(key, value);\n }\n return value;\n }\n\n /**\n * Set key-value pair (O(log n) for tree operations, O(1) for cache)\n */\n set(key: K, value: V): void {\n const isUpdate = this.cache.has(key);\n\n if (isUpdate) {\n this.cache.delete(key);\n } else {\n if (this.cache.size >= this.maxSize) {\n // Remove oldest entry (first item in map)\n const firstKey = this.cache.keys().next().value;\n if (firstKey) {\n this.cache.delete(firstKey);\n this.tree.delete(firstKey);\n }\n }\n // Add to tree index for new keys\n this.tree.insert(key);\n }\n\n this.cache.set(key, value);\n }\n\n /**\n * Find exact key using tree search (O(log n))\n */\n findExact(key: K): V | undefined {\n const foundKey = this.tree.find(key);\n if (foundKey !== null) {\n return this.get(key);\n }\n return undefined;\n }\n\n /**\n * Find keys within distance of center point (O(log n + k) where k is result count)\n * Returns empty array if no keys found in range\n */\n findNearestInRange(center: K, distance: K): Array<{ key: K; value: V }> {\n const nearestKeys = this.tree.findNearestInRange(center, distance);\n const result: Array<{ key: K; value: V }> = [];\n\n for (const key of nearestKeys) {\n const value = this.get(key);\n if (value !== undefined) {\n result.push({ key, value });\n }\n }\n\n return result;\n }\n\n /**\n * Find all key-value pairs in range [start, end] (O(log n + k) where k is result count)\n */\n findRange(start: K, end: K): Array<{ key: K; value: V }> {\n const keys = this.tree.findRange(start, end);\n const result: Array<{ key: K; value: V }> = [];\n\n for (const key of keys) {\n const value = this.get(key);\n if (value !== undefined) {\n result.push({ key, value });\n }\n }\n\n return result;\n }\n\n /**\n * Get all keys in sorted order (O(n))\n */\n getSortedKeys(): ReadonlyArray<K> {\n return this.tree.getAllSorted();\n }\n\n has(key: K): boolean {\n return this.cache.has(key);\n }\n\n delete(key: K): boolean {\n const deleted = this.cache.delete(key);\n if (deleted) {\n this.tree.delete(key);\n }\n return deleted;\n }\n\n clear(): void {\n this.cache.clear();\n this.tree = new RedBlackTree(this.compareFn);\n }\n\n get size(): number {\n return this.cache.size;\n }\n}\n"],"mappings":";;;;AAGA,IAAa,WAAb,MAA4B;CAI1B,YAAY,SAAiB;+BAHb,IAAI,KAAW;AAI7B,OAAK,UAAU;;CAGjB,IAAI,KAAuB;EACzB,MAAM,QAAQ,KAAK,MAAM,IAAI,IAAI;AACjC,MAAI,OAAO;AAET,QAAK,MAAM,OAAO,IAAI;AACtB,QAAK,MAAM,IAAI,KAAK,MAAM;;AAE5B,SAAO;;CAGT,IAAI,KAAQ,OAAgB;AAC1B,MAAI,KAAK,MAAM,IAAI,IAAI,CACrB,MAAK,MAAM,OAAO,IAAI;WACb,KAAK,MAAM,QAAQ,KAAK,SAAS;GAE1C,MAAM,WAAW,KAAK,MAAM,MAAM,CAAC,MAAM,CAAC;AAC1C,OAAI,SACF,MAAK,MAAM,OAAO,SAAS;;AAG/B,OAAK,MAAM,IAAI,KAAK,MAAM;;CAG5B,IAAI,KAAiB;AACnB,SAAO,KAAK,MAAM,IAAI,IAAI;;CAG5B,OAAO,KAAiB;AACtB,SAAO,KAAK,MAAM,OAAO,IAAI;;CAG/B,QAAc;AACZ,OAAK,MAAM,OAAO;;CAGpB,IAAI,OAAe;AACjB,SAAO,KAAK,MAAM;;;;;;;AAQtB,IAAa,oBAAb,MAAkC;CAMhC,YAAY,cAAsB;+BALlB,IAAI,KAA8B;+BAClC,IAAI,KAAgB;qBACd;AAIpB,OAAK,eAAe;;CAGtB,IAAI,KAA0C;EAC5C,MAAM,QAAQ,KAAK,MAAM,IAAI,IAAI;AACjC,MAAI,OAAO;GAET,MAAM,OAAO,KAAK,MAAM,IAAI,IAAI,IAAI;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M"}
|
|
1
|
+
{"version":3,"file":"LRUCache.js","names":[],"sources":["../../src/utils/LRUCache.ts"],"sourcesContent":["/**\n * A simple LRU (Least Recently Used) cache implementation\n */\nexport class LRUCache<K, V> {\n private cache = new Map<K, V>();\n private readonly maxSize: number;\n\n constructor(maxSize: number) {\n this.maxSize = maxSize;\n }\n\n get(key: K): V | undefined {\n const value = this.cache.get(key);\n if (value) {\n // Refresh position by removing and re-adding\n this.cache.delete(key);\n this.cache.set(key, value);\n }\n return value;\n }\n\n set(key: K, value: V): void {\n if (this.cache.has(key)) {\n this.cache.delete(key);\n } else if (this.cache.size >= this.maxSize) {\n // Remove oldest entry (first item in map)\n const firstKey = this.cache.keys().next().value;\n if (firstKey) {\n this.cache.delete(firstKey);\n }\n }\n this.cache.set(key, value);\n }\n\n has(key: K): boolean {\n return this.cache.has(key);\n }\n\n delete(key: K): boolean {\n return this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n get size(): number {\n return this.cache.size;\n }\n}\n\n/**\n * Size-aware LRU cache that tracks memory usage in bytes\n * Evicts entries when total size exceeds the maximum\n */\nexport class SizeAwareLRUCache<K> {\n private cache = new Map<K, Promise<ArrayBuffer>>();\n private sizes = new Map<K, number>();\n private currentSize = 0;\n private readonly maxSizeBytes: number;\n\n constructor(maxSizeBytes: number) {\n this.maxSizeBytes = maxSizeBytes;\n }\n\n get(key: K): Promise<ArrayBuffer> | undefined {\n const value = this.cache.get(key);\n if (value) {\n // Refresh position by removing and re-adding\n const size = this.sizes.get(key) || 0;\n this.cache.delete(key);\n this.cache.set(key, value);\n this.sizes.delete(key);\n this.sizes.set(key, size);\n }\n return value;\n }\n\n set(key: K, value: Promise<ArrayBuffer>): void {\n // If key already exists, remove it first\n if (this.cache.has(key)) {\n const oldSize = this.sizes.get(key) || 0;\n this.currentSize -= oldSize;\n this.cache.delete(key);\n this.sizes.delete(key);\n }\n\n // Track the size when the promise resolves\n const sizeTrackingPromise = value\n .then((buffer) => {\n const bufferSize = buffer.byteLength;\n this.sizes.set(key, bufferSize);\n this.currentSize += bufferSize;\n\n // Evict oldest entries if we exceed the size limit\n this.evictIfNecessary();\n\n return buffer;\n })\n .catch((error) => {\n // If the promise fails, clean up the entry\n this.cache.delete(key);\n this.sizes.delete(key);\n throw error;\n });\n\n this.cache.set(key, sizeTrackingPromise);\n }\n\n private evictIfNecessary(): void {\n while (this.currentSize > this.maxSizeBytes && this.cache.size > 0) {\n // Remove oldest entry (first item in map)\n const firstKey = this.cache.keys().next().value;\n if (firstKey) {\n const size = this.sizes.get(firstKey) || 0;\n this.currentSize -= size;\n this.cache.delete(firstKey);\n this.sizes.delete(firstKey);\n } else {\n break;\n }\n }\n }\n\n has(key: K): boolean {\n return this.cache.has(key);\n }\n\n delete(key: K): boolean {\n const size = this.sizes.get(key) || 0;\n this.currentSize -= size;\n this.sizes.delete(key);\n return this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n this.sizes.clear();\n this.currentSize = 0;\n }\n\n get size(): number {\n return this.cache.size;\n }\n\n get currentSizeBytes(): number {\n return this.currentSize;\n }\n\n get maxSize(): number {\n return this.maxSizeBytes;\n }\n}\n\n/**\n * Red-Black Tree node colors\n */\nenum Color {\n RED = \"RED\",\n BLACK = \"BLACK\",\n}\n\n/**\n * Red-Black Tree node for ordered key storage\n */\nclass RBTreeNode<K> {\n constructor(\n public key: K,\n public color: Color = Color.RED,\n public left: RBTreeNode<K> | null = null,\n public right: RBTreeNode<K> | null = null,\n public parent: RBTreeNode<K> | null = null,\n ) {}\n}\n\n/**\n * Red-Black Tree implementation for O(log n) operations\n * Supports insert, delete, search, range queries, and nearest neighbor\n */\nclass RedBlackTree<K> {\n private root: RBTreeNode<K> | null = null;\n private readonly compareFn: (a: K, b: K) => number;\n\n constructor(compareFn: (a: K, b: K) => number) {\n this.compareFn = compareFn;\n }\n\n insert(key: K): void {\n const node = new RBTreeNode(key);\n\n if (!this.root) {\n this.root = node;\n node.color = Color.BLACK;\n return;\n }\n\n this.insertNode(node);\n this.fixInsert(node);\n }\n\n delete(key: K): boolean {\n const node = this.findNode(key);\n if (!node) return false;\n\n this.deleteNode(node);\n return true;\n }\n\n find(key: K): K | null {\n const node = this.findNode(key);\n return node ? node.key : null;\n }\n\n findNearestInRange(center: K, distance: K): K[] {\n // Calculate the range bounds\n const start = this.subtractDistance(center, distance);\n const end = this.addDistance(center, distance);\n\n // Use existing range search (O(log n + k))\n return this.findRange(start, end);\n }\n\n private subtractDistance(center: K, distance: K): K {\n if (typeof center === \"number\" && typeof distance === \"number\") {\n return (center - distance) as K;\n }\n\n // For strings, we can't easily subtract distance, so just return center\n // This means string searches will be exact matches only\n return center;\n }\n\n private addDistance(center: K, distance: K): K {\n if (typeof center === \"number\" && typeof distance === \"number\") {\n return (center + distance) as K;\n }\n\n // For strings, we can't easily add distance, so just return center\n // This means string searches will be exact matches only\n return center;\n }\n\n findRange(start: K, end: K): K[] {\n const result: K[] = [];\n this.inorderRange(this.root, start, end, result);\n return result;\n }\n\n getAllSorted(): K[] {\n const result: K[] = [];\n this.inorder(this.root, result);\n return result;\n }\n\n private findNode(key: K): RBTreeNode<K> | null {\n let current = this.root;\n\n while (current) {\n const cmp = this.compareFn(key, current.key);\n if (cmp === 0) return current;\n current = cmp < 0 ? current.left : current.right;\n }\n\n return null;\n }\n\n private insertNode(node: RBTreeNode<K>): void {\n let parent = null;\n let current = this.root;\n\n while (current) {\n parent = current;\n const cmp = this.compareFn(node.key, current.key);\n current = cmp < 0 ? current.left : current.right;\n }\n\n node.parent = parent;\n if (!parent) {\n this.root = node;\n } else {\n const cmp = this.compareFn(node.key, parent.key);\n if (cmp < 0) {\n parent.left = node;\n } else {\n parent.right = node;\n }\n }\n }\n\n private fixInsert(node: RBTreeNode<K>): void {\n while (node.parent && node.parent.color === Color.RED) {\n if (node.parent === node.parent.parent?.left) {\n const uncle = node.parent.parent.right;\n\n if (uncle?.color === Color.RED) {\n node.parent.color = Color.BLACK;\n uncle.color = Color.BLACK;\n node.parent.parent.color = Color.RED;\n node = node.parent.parent;\n } else {\n if (node === node.parent.right) {\n node = node.parent;\n this.rotateLeft(node);\n }\n\n if (node.parent) {\n node.parent.color = Color.BLACK;\n if (node.parent.parent) {\n node.parent.parent.color = Color.RED;\n this.rotateRight(node.parent.parent);\n }\n }\n }\n } else {\n const uncle = node.parent.parent?.left;\n\n if (uncle?.color === Color.RED) {\n node.parent.color = Color.BLACK;\n uncle.color = Color.BLACK;\n if (node.parent.parent) {\n node.parent.parent.color = Color.RED;\n node = node.parent.parent;\n }\n } else {\n if (node === node.parent.left) {\n node = node.parent;\n this.rotateRight(node);\n }\n\n if (node.parent) {\n node.parent.color = Color.BLACK;\n if (node.parent.parent) {\n node.parent.parent.color = Color.RED;\n this.rotateLeft(node.parent.parent);\n }\n }\n }\n }\n }\n\n if (this.root) {\n this.root.color = Color.BLACK;\n }\n }\n\n private deleteNode(node: RBTreeNode<K>): void {\n let y = node;\n let yOriginalColor = y.color;\n let x: RBTreeNode<K> | null;\n\n if (!node.left) {\n x = node.right;\n this.transplant(node, node.right);\n } else if (!node.right) {\n x = node.left;\n this.transplant(node, node.left);\n } else {\n y = this.minimum(node.right);\n yOriginalColor = y.color;\n x = y.right;\n\n if (y.parent === node) {\n if (x) x.parent = y;\n } else {\n this.transplant(y, y.right);\n y.right = node.right;\n if (y.right) y.right.parent = y;\n }\n\n this.transplant(node, y);\n y.left = node.left;\n if (y.left) y.left.parent = y;\n y.color = node.color;\n }\n\n if (yOriginalColor === Color.BLACK && x) {\n this.fixDelete(x);\n }\n }\n\n private fixDelete(node: RBTreeNode<K>): void {\n while (node !== this.root && node.color === Color.BLACK) {\n if (node === node.parent?.left) {\n let sibling = node.parent.right;\n\n if (sibling?.color === Color.RED) {\n sibling.color = Color.BLACK;\n node.parent.color = Color.RED;\n this.rotateLeft(node.parent);\n sibling = node.parent.right;\n }\n\n if (\n sibling?.left?.color !== Color.RED &&\n sibling?.right?.color !== Color.RED\n ) {\n if (sibling) {\n sibling.color = Color.RED;\n }\n node = node.parent;\n } else {\n if (sibling?.right?.color !== Color.RED) {\n if (sibling.left) sibling.left.color = Color.BLACK;\n sibling.color = Color.RED;\n this.rotateRight(sibling);\n sibling = node.parent.right;\n }\n\n if (sibling) {\n sibling.color = node.parent.color;\n node.parent.color = Color.BLACK;\n if (sibling.right) sibling.right.color = Color.BLACK;\n this.rotateLeft(node.parent);\n }\n if (!this.root) {\n throw new Error(\"Root is null\");\n }\n node = this.root;\n }\n } else {\n let sibling = node.parent?.left;\n\n if (sibling?.color === Color.RED) {\n sibling.color = Color.BLACK;\n if (node.parent) node.parent.color = Color.RED;\n if (node.parent) this.rotateRight(node.parent);\n sibling = node.parent?.left;\n }\n\n if (\n sibling?.right?.color !== Color.RED &&\n sibling?.left?.color !== Color.RED\n ) {\n if (sibling) {\n sibling.color = Color.RED;\n }\n if (node.parent === null) {\n throw new Error(\"Node parent is null\");\n }\n node = node.parent;\n } else {\n if (sibling?.left?.color !== Color.RED) {\n if (sibling.right) sibling.right.color = Color.BLACK;\n sibling.color = Color.RED;\n this.rotateLeft(sibling);\n sibling = node.parent?.left;\n }\n\n if (sibling) {\n sibling.color = node.parent?.color || Color.BLACK;\n if (node.parent) node.parent.color = Color.BLACK;\n if (sibling.left) sibling.left.color = Color.BLACK;\n if (node.parent) this.rotateRight(node.parent);\n }\n if (!this.root) {\n throw new Error(\"Root is null\");\n }\n node = this.root;\n }\n }\n }\n\n node.color = Color.BLACK;\n }\n\n private rotateLeft(node: RBTreeNode<K>): void {\n const rightChild = node.right;\n if (!rightChild) {\n throw new Error(\"Right child is null\");\n }\n node.right = rightChild.left;\n\n if (rightChild.left) {\n rightChild.left.parent = node;\n }\n\n rightChild.parent = node.parent;\n\n if (!node.parent) {\n this.root = rightChild;\n } else if (node === node.parent.left) {\n node.parent.left = rightChild;\n } else {\n node.parent.right = rightChild;\n }\n\n rightChild.left = node;\n node.parent = rightChild;\n }\n\n private rotateRight(node: RBTreeNode<K>): void {\n const leftChild = node.left;\n if (!leftChild) {\n throw new Error(\"Left child is null\");\n }\n node.left = leftChild.right;\n\n if (leftChild.right) {\n leftChild.right.parent = node;\n }\n\n leftChild.parent = node.parent;\n\n if (!node.parent) {\n this.root = leftChild;\n } else if (node === node.parent.right) {\n node.parent.right = leftChild;\n } else {\n node.parent.left = leftChild;\n }\n\n leftChild.right = node;\n node.parent = leftChild;\n }\n\n private transplant(u: RBTreeNode<K>, v: RBTreeNode<K> | null): void {\n if (!u.parent) {\n this.root = v;\n } else if (u === u.parent.left) {\n u.parent.left = v;\n } else {\n u.parent.right = v;\n }\n\n if (v) {\n v.parent = u.parent;\n }\n }\n\n private minimum(node: RBTreeNode<K>): RBTreeNode<K> {\n while (node.left) {\n node = node.left;\n }\n return node;\n }\n\n private inorder(node: RBTreeNode<K> | null, result: K[]): void {\n if (node) {\n this.inorder(node.left, result);\n result.push(node.key);\n this.inorder(node.right, result);\n }\n }\n\n private inorderRange(\n node: RBTreeNode<K> | null,\n start: K,\n end: K,\n result: K[],\n ): void {\n if (!node) return;\n\n const startCmp = this.compareFn(node.key, start);\n const endCmp = this.compareFn(node.key, end);\n\n if (startCmp > 0) {\n this.inorderRange(node.left, start, end, result);\n }\n\n if (startCmp >= 0 && endCmp <= 0) {\n result.push(node.key);\n }\n\n if (endCmp < 0) {\n this.inorderRange(node.right, start, end, result);\n }\n }\n}\n\n/**\n * LRU cache with binary search capabilities using Red-Black tree\n * All operations are O(log n) for ordered queries and O(1) for LRU operations\n */\nexport class OrderedLRUCache<K extends number | string, V> {\n private cache = new Map<K, V>();\n private tree: RedBlackTree<K>;\n private readonly maxSize: number;\n private readonly compareFn: (a: K, b: K) => number;\n\n constructor(maxSize: number, compareFn?: (a: K, b: K) => number) {\n this.maxSize = maxSize;\n this.compareFn = compareFn || ((a, b) => (a < b ? -1 : a > b ? 1 : 0));\n this.tree = new RedBlackTree(this.compareFn);\n }\n\n /**\n * Get value by exact key (O(1))\n */\n get(key: K): V | undefined {\n const value = this.cache.get(key);\n if (value) {\n // Refresh position by removing and re-adding\n this.cache.delete(key);\n this.cache.set(key, value);\n }\n return value;\n }\n\n /**\n * Set key-value pair (O(log n) for tree operations, O(1) for cache)\n */\n set(key: K, value: V): void {\n const isUpdate = this.cache.has(key);\n\n if (isUpdate) {\n this.cache.delete(key);\n } else {\n if (this.cache.size >= this.maxSize) {\n // Remove oldest entry (first item in map)\n const firstKey = this.cache.keys().next().value;\n if (firstKey) {\n this.cache.delete(firstKey);\n this.tree.delete(firstKey);\n }\n }\n // Add to tree index for new keys\n this.tree.insert(key);\n }\n\n this.cache.set(key, value);\n }\n\n /**\n * Find exact key using tree search (O(log n))\n */\n findExact(key: K): V | undefined {\n const foundKey = this.tree.find(key);\n if (foundKey !== null) {\n return this.get(key);\n }\n return undefined;\n }\n\n /**\n * Find keys within distance of center point (O(log n + k) where k is result count)\n * Returns empty array if no keys found in range\n */\n findNearestInRange(center: K, distance: K): Array<{ key: K; value: V }> {\n const nearestKeys = this.tree.findNearestInRange(center, distance);\n const result: Array<{ key: K; value: V }> = [];\n\n for (const key of nearestKeys) {\n const value = this.get(key);\n if (value !== undefined) {\n result.push({ key, value });\n }\n }\n\n return result;\n }\n\n /**\n * Find all key-value pairs in range [start, end] (O(log n + k) where k is result count)\n */\n findRange(start: K, end: K): Array<{ key: K; value: V }> {\n const keys = this.tree.findRange(start, end);\n const result: Array<{ key: K; value: V }> = [];\n\n for (const key of keys) {\n const value = this.get(key);\n if (value !== undefined) {\n result.push({ key, value });\n }\n }\n\n return result;\n }\n\n /**\n * Get all keys in sorted order (O(n))\n */\n getSortedKeys(): ReadonlyArray<K> {\n return this.tree.getAllSorted();\n }\n\n has(key: K): boolean {\n return this.cache.has(key);\n }\n\n delete(key: K): boolean {\n const deleted = this.cache.delete(key);\n if (deleted) {\n this.tree.delete(key);\n }\n return deleted;\n }\n\n clear(): void {\n this.cache.clear();\n this.tree = new RedBlackTree(this.compareFn);\n }\n\n get size(): number {\n return this.cache.size;\n }\n}\n"],"m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ures time values align with frame boundaries for consistent rendering.
|
|
5
|
+
*/
|
|
6
|
+
function quantizeToFrameTimeS(timeSeconds, fps) {
|
|
7
|
+
if (!fps || fps <= 0) return timeSeconds;
|
|
8
|
+
const frameDurationS = 1 / fps;
|
|
9
|
+
return Math.round(timeSeconds / frameDurationS) * frameDurationS;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { quantizeToFrameTimeS };
|
|
14
|
+
//# sourceMappingURL=frameTime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frameTime.js","names":[],"sources":["../../src/utils/frameTime.ts"],"sourcesContent":["/**\n * Frame timing utilities for quantizing time values to frame boundaries.\n * These utilities ensure consistent frame-aligned timing across the codebase.\n */\n\n/** Default FPS when none is specified */\nexport const DEFAULT_FPS = 30;\n\n/**\n * Calculate the duration of a single frame in milliseconds.\n */\nexport function calculateFrameIntervalMs(fps: number): number {\n if (fps <= 0) return 1000 / DEFAULT_FPS;\n return 1000 / fps;\n}\n\n/**\n * Quantize a time value (in milliseconds) to the nearest frame boundary.\n * This ensures frame markers align perfectly with playhead position.\n */\nexport function quantizeToFrameTimeMs(timeMs: number, fps: number): number {\n if (!fps || fps <= 0) return timeMs;\n const frameDurationMs = calculateFrameIntervalMs(fps);\n return Math.round(timeMs / frameDurationMs) * frameDurationMs;\n}\n\n/**\n * Quantize a time value (in seconds) to the nearest frame boundary.\n * This ensures time values align with frame boundaries for consistent rendering.\n */\nexport function quantizeToFrameTimeS(timeSeconds: number, fps: number): number {\n if (!fps || fps <= 0) return timeSeconds;\n const frameDurationS = 1 / fps;\n return Math.round(timeSeconds / frameDurationS) * frameDurationS;\n}\n\n/**\n * Clamp and quantize a seek time to valid range.\n * Prevents \"Sample not found\" errors at video boundaries.\n * \n * @param desiredSeekTimeMs - The desired seek time in milliseconds\n * @param durationMs - The total duration in milliseconds\n * @param fps - Frames per second (defaults to 30)\n * @returns Clamped and quantized time in milliseconds\n */\nexport function clampAndQuantizeSeekTimeMs(\n desiredSeekTimeMs: number,\n durationMs: number,\n fps: number = DEFAULT_FPS,\n): number {\n if (durationMs <= 0) return 0;\n\n // Quantize to frame boundaries\n const quantizedMs = quantizeToFrameTimeMs(desiredSeekTimeMs, fps);\n\n // Clamp to valid range [0, lastFrameTime]\n // The last valid frame is at durationMs - frameDurationMs to ensure we don't\n // seek past the last decodable frame\n const frameDurationMs = calculateFrameIntervalMs(fps);\n const maxValidTime = Math.max(0, durationMs - frameDurationMs);\n return Math.max(0, Math.min(quantizedMs, maxValidTime));\n}\n\n\n\n\n"],"mappings":";;;;;AA8BA,SAAgB,qBAAqB,aAAqB,KAAqB;AAC7E,KAAI,CAAC,OAAO,OAAO,EAAG,QAAO;CAC7B,MAAM,iBAAiB,IAAI;AAC3B,QAAO,KAAK,MAAM,cAAc,eAAe,GAAG"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editframe/elements",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0-beta.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"typecheck": "tsc --noEmit --emitDeclarationOnly false",
|
|
8
8
|
"build": "tsdown && node scripts/build-css.js",
|
|
9
9
|
"build:watch": "tsdown --watch",
|
|
10
|
-
"typedoc": "typedoc --json ./types.json --plugin typedoc-plugin-zod --excludeExternals ./src && jq -c . ./types.json > ./types.tmp.json && mv ./types.tmp.json ./types.json"
|
|
10
|
+
"typedoc": "(typedoc --json ./types.json --plugin typedoc-plugin-zod --excludeExternals ./src || true) && ([ -f ./types.json ] && jq -c . ./types.json > ./types.tmp.json && mv ./types.tmp.json ./types.json || true)"
|
|
11
11
|
},
|
|
12
12
|
"author": "",
|
|
13
13
|
"license": "UNLICENSED",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@bramus/style-observer": "^1.3.0",
|
|
16
|
-
"@editframe/assets": "0.
|
|
16
|
+
"@editframe/assets": "0.31.0-beta.0",
|
|
17
17
|
"@lit/context": "^1.1.6",
|
|
18
18
|
"@lit/task": "^1.0.3",
|
|
19
19
|
"@opentelemetry/api": "^1.9.0",
|