@tomaszjarosz/react-visualizers 0.2.4 → 0.2.10
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 +73 -31
- package/dist/index.cjs +440 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +440 -61
- package/dist/index.js.map +1 -1
- package/package.json +22 -3
package/dist/index.cjs
CHANGED
|
@@ -1496,11 +1496,64 @@ const BinarySearchVisualizerComponent = ({
|
|
|
1496
1496
|
] }) }),
|
|
1497
1497
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
1498
1498
|
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 350, children: [
|
|
1499
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-green-50 to-emerald-50 rounded-xl border-2 border-green-200", children: [
|
|
1500
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-green-800 mb-3 flex items-center gap-2", children: [
|
|
1501
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: "🎯" }),
|
|
1502
|
+
" Binary Search Invariant"
|
|
1503
|
+
] }),
|
|
1504
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono text-sm bg-white rounded-lg p-3 border border-green-200", children: [
|
|
1505
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-center text-green-700 font-bold mb-2", children: "target ∈ arr[left..right]" }),
|
|
1506
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-gray-500 text-center", children: "If target exists, it must be within current search bounds" })
|
|
1507
|
+
] }),
|
|
1508
|
+
left <= right && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-3 p-2 bg-white rounded-lg border border-green-200", children: [
|
|
1509
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between items-center text-xs", children: [
|
|
1510
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1511
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold text-green-700", children: "Search space:" }),
|
|
1512
|
+
" ",
|
|
1513
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-mono", children: [
|
|
1514
|
+
"[",
|
|
1515
|
+
left,
|
|
1516
|
+
"..",
|
|
1517
|
+
right,
|
|
1518
|
+
"]"
|
|
1519
|
+
] }),
|
|
1520
|
+
" = ",
|
|
1521
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-bold text-green-600", children: right - left + 1 }),
|
|
1522
|
+
" elements"
|
|
1523
|
+
] }),
|
|
1524
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-500", children: currentStep > 0 && /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
1525
|
+
"Eliminated: ",
|
|
1526
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-bold text-red-500", children: [
|
|
1527
|
+
Math.round((1 - (right - left + 1) / array.length) * 100),
|
|
1528
|
+
"%"
|
|
1529
|
+
] })
|
|
1530
|
+
] }) })
|
|
1531
|
+
] }),
|
|
1532
|
+
mid >= 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 text-xs text-center text-gray-600", children: [
|
|
1533
|
+
"mid = ⌊(",
|
|
1534
|
+
left,
|
|
1535
|
+
" + ",
|
|
1536
|
+
right,
|
|
1537
|
+
") / 2⌋ = ",
|
|
1538
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-bold text-purple-600", children: mid })
|
|
1539
|
+
] })
|
|
1540
|
+
] }),
|
|
1541
|
+
found === true && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 p-2 bg-green-100 rounded-lg border border-green-300 text-center", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-green-800 font-bold", children: [
|
|
1542
|
+
"✓ Found in ",
|
|
1543
|
+
currentStep,
|
|
1544
|
+
" steps (log₂",
|
|
1545
|
+
array.length,
|
|
1546
|
+
" ≈ ",
|
|
1547
|
+
Math.ceil(Math.log2(array.length)),
|
|
1548
|
+
" max)"
|
|
1549
|
+
] }) }),
|
|
1550
|
+
found === false && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 p-2 bg-red-100 rounded-lg border border-red-300 text-center", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-red-800 font-bold", children: "✗ Not found - search space exhausted" }) })
|
|
1551
|
+
] }),
|
|
1499
1552
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center gap-1 flex-wrap mb-4", children: array.map((value, index) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center", children: [
|
|
1500
1553
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1501
1554
|
"div",
|
|
1502
1555
|
{
|
|
1503
|
-
className: `w-10 h-10 flex items-center justify-center rounded-lg font-medium text-sm transition-
|
|
1556
|
+
className: `w-10 h-10 flex items-center justify-center rounded-lg font-medium text-sm transition-colors duration-300 ${getElementStyle(index)}`,
|
|
1504
1557
|
children: value
|
|
1505
1558
|
}
|
|
1506
1559
|
),
|
|
@@ -2371,7 +2424,7 @@ const SortingVisualizerComponent = ({
|
|
|
2371
2424
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-end justify-center gap-1 h-48 bg-gray-50 rounded-lg p-4", children: bars.map((bar, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2372
2425
|
"div",
|
|
2373
2426
|
{
|
|
2374
|
-
className: `${getBarColor(bar.state)} rounded-t transition-
|
|
2427
|
+
className: `${getBarColor(bar.state)} rounded-t transition-colors duration-200 flex items-end justify-center relative group`,
|
|
2375
2428
|
style: {
|
|
2376
2429
|
height: `${bar.value / maxValue * 100}%`,
|
|
2377
2430
|
width: `${Math.max(100 / bars.length - 1, 8)}%`,
|
|
@@ -2831,7 +2884,7 @@ const SortingComparisonVisualizerComponent = ({
|
|
|
2831
2884
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-3", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-end justify-center gap-0.5 h-32 bg-gray-50 rounded p-2", children: step.array.map((value, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2832
2885
|
"div",
|
|
2833
2886
|
{
|
|
2834
|
-
className: `${getBarColor(step, index)} rounded-t transition-
|
|
2887
|
+
className: `${getBarColor(step, index)} rounded-t transition-colors duration-150`,
|
|
2835
2888
|
style: {
|
|
2836
2889
|
height: `${value / maxValue * 100}%`,
|
|
2837
2890
|
width: `${Math.max(100 / step.array.length - 1, 6)}%`,
|
|
@@ -4142,6 +4195,25 @@ const GraphVisualizerComponent = ({
|
|
|
4142
4195
|
] }) }),
|
|
4143
4196
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
4144
4197
|
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 400, children: [
|
|
4198
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-purple-50 to-indigo-50 rounded-xl border-2 border-purple-200", children: [
|
|
4199
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-purple-800 mb-3 flex items-center gap-2", children: [
|
|
4200
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: "🔍" }),
|
|
4201
|
+
" DFS vs BFS"
|
|
4202
|
+
] }),
|
|
4203
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 text-xs", children: [
|
|
4204
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: `p-2 rounded-lg border ${algorithm === "dfs" ? "bg-purple-100 border-purple-300" : "bg-gray-100 border-gray-300"}`, children: [
|
|
4205
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-bold text-purple-700", children: "Depth-First (DFS)" }),
|
|
4206
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-purple-600", children: "Uses: Stack" }),
|
|
4207
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-purple-500", children: "Go deep before wide" })
|
|
4208
|
+
] }),
|
|
4209
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: `p-2 rounded-lg border ${algorithm === "bfs" ? "bg-indigo-100 border-indigo-300" : "bg-gray-100 border-gray-300"}`, children: [
|
|
4210
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-bold text-indigo-700", children: "Breadth-First (BFS)" }),
|
|
4211
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-indigo-600", children: "Uses: Queue" }),
|
|
4212
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-indigo-500", children: "Level by level" })
|
|
4213
|
+
] })
|
|
4214
|
+
] }),
|
|
4215
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 text-[10px] text-gray-600 text-center", children: "Both O(V+E) time • DFS for paths/cycles • BFS for shortest path (unweighted)" })
|
|
4216
|
+
] }),
|
|
4145
4217
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-4", children: [
|
|
4146
4218
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 bg-gray-50 rounded-lg", children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { viewBox: "0 0 400 300", className: "w-full h-64", children: [
|
|
4147
4219
|
graph.edges.map((edge, index) => {
|
|
@@ -4166,7 +4238,7 @@ const GraphVisualizerComponent = ({
|
|
|
4166
4238
|
cx: node.x,
|
|
4167
4239
|
cy: node.y,
|
|
4168
4240
|
r: 20,
|
|
4169
|
-
className: `${getNodeColor(node.id)} stroke-2 transition-
|
|
4241
|
+
className: `${getNodeColor(node.id)} stroke-2 transition-colors duration-300`
|
|
4170
4242
|
}
|
|
4171
4243
|
),
|
|
4172
4244
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -4499,6 +4571,40 @@ const HashMapVisualizerComponent = ({
|
|
|
4499
4571
|
] }) }),
|
|
4500
4572
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
4501
4573
|
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 350, className: showCode ? "flex-1" : "w-full", children: [
|
|
4574
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-indigo-50 to-purple-50 rounded-xl border-2 border-indigo-200", children: [
|
|
4575
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-indigo-800 mb-3 flex items-center gap-2", children: [
|
|
4576
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: "#️⃣" }),
|
|
4577
|
+
" Hash Function"
|
|
4578
|
+
] }),
|
|
4579
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono text-sm bg-white rounded-lg p-3 border border-indigo-200", children: [
|
|
4580
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-center text-indigo-700 font-bold mb-2", children: "index = hashCode(key) % capacity" }),
|
|
4581
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-gray-500 text-center", children: "Same key → same index (deterministic) • Different keys may collide → chaining" })
|
|
4582
|
+
] }),
|
|
4583
|
+
stepData.hash !== void 0 && stepData.key && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 p-3 bg-white rounded-lg border border-indigo-200", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs text-center", children: [
|
|
4584
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono mb-1", children: [
|
|
4585
|
+
"hashCode(",
|
|
4586
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-indigo-600 font-bold", children: [
|
|
4587
|
+
'"',
|
|
4588
|
+
stepData.key,
|
|
4589
|
+
'"'
|
|
4590
|
+
] }),
|
|
4591
|
+
") = ",
|
|
4592
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-purple-600 font-bold", children: stepData.hash })
|
|
4593
|
+
] }),
|
|
4594
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono", children: [
|
|
4595
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-purple-600", children: stepData.hash }),
|
|
4596
|
+
" % ",
|
|
4597
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-600", children: BUCKET_COUNT$1 }),
|
|
4598
|
+
" = ",
|
|
4599
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-indigo-600 font-bold text-lg", children: stepData.bucketIndex })
|
|
4600
|
+
] }),
|
|
4601
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 text-indigo-600 text-lg", children: [
|
|
4602
|
+
"↓ bucket[",
|
|
4603
|
+
stepData.bucketIndex,
|
|
4604
|
+
"]"
|
|
4605
|
+
] })
|
|
4606
|
+
] }) })
|
|
4607
|
+
] }),
|
|
4502
4608
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
|
|
4503
4609
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-medium text-gray-700 mb-2", children: [
|
|
4504
4610
|
"Bucket Array (capacity: ",
|
|
@@ -4529,22 +4635,6 @@ const HashMapVisualizerComponent = ({
|
|
|
4529
4635
|
] }, eIdx)) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-gray-400 mt-1", children: "∅" }) })
|
|
4530
4636
|
] }, idx)) })
|
|
4531
4637
|
] }),
|
|
4532
|
-
stepData.hash !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-4 p-3 bg-gray-100 rounded-lg", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs text-gray-600", children: [
|
|
4533
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium", children: "Hash Calculation:" }),
|
|
4534
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-1 font-mono text-indigo-600", children: [
|
|
4535
|
-
'hashCode("',
|
|
4536
|
-
stepData.key,
|
|
4537
|
-
'") = ',
|
|
4538
|
-
stepData.hash
|
|
4539
|
-
] }),
|
|
4540
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono text-purple-600", children: [
|
|
4541
|
-
stepData.hash,
|
|
4542
|
-
" % ",
|
|
4543
|
-
BUCKET_COUNT$1,
|
|
4544
|
-
" = ",
|
|
4545
|
-
stepData.bucketIndex
|
|
4546
|
-
] })
|
|
4547
|
-
] }) }),
|
|
4548
4638
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4549
4639
|
StatusPanel,
|
|
4550
4640
|
{
|
|
@@ -5217,6 +5307,27 @@ const LinkedListVisualizerComponent = ({
|
|
|
5217
5307
|
] }) }),
|
|
5218
5308
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
5219
5309
|
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 350, className: showCode ? "flex-1" : "w-full", children: [
|
|
5310
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-xl border-2 border-blue-200", children: [
|
|
5311
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-blue-800 mb-3 flex items-center gap-2", children: [
|
|
5312
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: "🔗" }),
|
|
5313
|
+
" LinkedList vs ArrayList"
|
|
5314
|
+
] }),
|
|
5315
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-3 gap-2 text-xs", children: [
|
|
5316
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-white p-2 rounded-lg border border-blue-200 text-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-semibold text-gray-700 mb-1", children: "Operation" }) }),
|
|
5317
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-blue-100 p-2 rounded-lg border border-blue-300 text-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-semibold text-blue-700 mb-1", children: "LinkedList" }) }),
|
|
5318
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-orange-100 p-2 rounded-lg border border-orange-300 text-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-semibold text-orange-700 mb-1", children: "ArrayList" }) }),
|
|
5319
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-white p-2 rounded-lg border border-gray-200 text-center font-medium", children: "add/remove (ends)" }),
|
|
5320
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-green-100 p-2 rounded-lg border border-green-300 text-center font-bold text-green-700", children: "O(1)" }),
|
|
5321
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-green-100 p-2 rounded-lg border border-green-300 text-center font-bold text-green-700", children: "O(1)*" }),
|
|
5322
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-white p-2 rounded-lg border border-gray-200 text-center font-medium", children: "add/remove (middle)" }),
|
|
5323
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-green-100 p-2 rounded-lg border border-green-300 text-center font-bold text-green-700", children: "O(1)**" }),
|
|
5324
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-red-100 p-2 rounded-lg border border-red-300 text-center font-bold text-red-700", children: "O(n)" }),
|
|
5325
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-white p-2 rounded-lg border border-gray-200 text-center font-medium", children: "get(index)" }),
|
|
5326
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-red-100 p-2 rounded-lg border border-red-300 text-center font-bold text-red-700", children: "O(n)" }),
|
|
5327
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-green-100 p-2 rounded-lg border border-green-300 text-center font-bold text-green-700", children: "O(1)" })
|
|
5328
|
+
] }),
|
|
5329
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 text-[10px] text-gray-500 text-center", children: "* amortized | ** if you have the node reference" })
|
|
5330
|
+
] }),
|
|
5220
5331
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
|
|
5221
5332
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-gray-700 mb-2", children: "Doubly-Linked List" }),
|
|
5222
5333
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-gray-50 rounded-lg p-4 overflow-x-auto", children: nodes.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 min-w-max", children: [
|
|
@@ -5225,7 +5336,7 @@ const LinkedListVisualizerComponent = ({
|
|
|
5225
5336
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
5226
5337
|
"div",
|
|
5227
5338
|
{
|
|
5228
|
-
className: `flex flex-col items-center transition-
|
|
5339
|
+
className: `flex flex-col items-center transition-colors ${node.id === highlightNode ? "scale-110" : ""}`,
|
|
5229
5340
|
children: [
|
|
5230
5341
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5231
5342
|
"div",
|
|
@@ -5601,6 +5712,7 @@ const LinkedHashMapVisualizerComponent = ({
|
|
|
5601
5712
|
});
|
|
5602
5713
|
const stepData = currentStepData || {
|
|
5603
5714
|
operation: "init",
|
|
5715
|
+
key: "",
|
|
5604
5716
|
buckets: [],
|
|
5605
5717
|
linkedOrder: [],
|
|
5606
5718
|
description: ""
|
|
@@ -5681,9 +5793,30 @@ const LinkedHashMapVisualizerComponent = ({
|
|
|
5681
5793
|
] }) }),
|
|
5682
5794
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
5683
5795
|
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 400, className: showCode ? "flex-1" : "w-full", children: [
|
|
5684
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-
|
|
5685
|
-
/* @__PURE__ */ jsxRuntime.
|
|
5686
|
-
|
|
5796
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-orange-50 to-amber-50 rounded-xl border-2 border-orange-200", children: [
|
|
5797
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-orange-800 mb-3 flex items-center gap-2", children: [
|
|
5798
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: "🔗" }),
|
|
5799
|
+
" LinkedHashMap = HashMap + LinkedList"
|
|
5800
|
+
] }),
|
|
5801
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
|
|
5802
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-white p-3 rounded-lg border border-orange-200", children: [
|
|
5803
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs font-semibold text-gray-700 mb-1", children: "🗂️ Hash Table" }),
|
|
5804
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-gray-500", children: "O(1) get/put • Same as HashMap" })
|
|
5805
|
+
] }),
|
|
5806
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-white p-3 rounded-lg border border-orange-200", children: [
|
|
5807
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs font-semibold text-gray-700 mb-1", children: "🔗 Doubly Linked List" }),
|
|
5808
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-[10px] text-gray-500", children: [
|
|
5809
|
+
accessOrder ? "Access order (LRU cache)" : "Insertion order",
|
|
5810
|
+
" • O(1) reorder"
|
|
5811
|
+
] })
|
|
5812
|
+
] })
|
|
5813
|
+
] }),
|
|
5814
|
+
stepData.operation === "access" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 p-2 bg-orange-100 rounded-lg border border-orange-300", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs text-center text-orange-800", children: [
|
|
5815
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-bold", children: "LRU Update:" }),
|
|
5816
|
+
' Entry "',
|
|
5817
|
+
stepData.key,
|
|
5818
|
+
'" moved to end of list (most recently used)'
|
|
5819
|
+
] }) })
|
|
5687
5820
|
] }),
|
|
5688
5821
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
|
|
5689
5822
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-medium text-gray-700 mb-2", children: [
|
|
@@ -5715,22 +5848,31 @@ const LinkedHashMapVisualizerComponent = ({
|
|
|
5715
5848
|
] }, eIdx)) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-gray-400 mt-1", children: "∅" }) })
|
|
5716
5849
|
] }, idx)) })
|
|
5717
5850
|
] }),
|
|
5718
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
|
|
5719
|
-
/* @__PURE__ */ jsxRuntime.
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
}
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5851
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-3 bg-gradient-to-r from-orange-100 to-amber-100 rounded-xl border-2 border-orange-300", children: [
|
|
5852
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-semibold text-orange-800 mb-2 flex items-center gap-2", children: [
|
|
5853
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "🔗" }),
|
|
5854
|
+
" ",
|
|
5855
|
+
accessOrder ? "Access Order (LRU: oldest → newest)" : "Insertion Order"
|
|
5856
|
+
] }),
|
|
5857
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-white rounded-lg p-3 border border-orange-200", children: [
|
|
5858
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap items-center gap-1", children: linkedOrder.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
5859
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-2 py-1 bg-gray-100 text-[10px] text-gray-600 rounded font-semibold", children: "HEAD" }),
|
|
5860
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-orange-400 font-bold", children: "→" }),
|
|
5861
|
+
linkedOrder.map((key, idx) => /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
|
|
5862
|
+
idx > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-orange-400 font-bold", children: "⇄" }),
|
|
5863
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5864
|
+
"div",
|
|
5865
|
+
{
|
|
5866
|
+
className: `px-3 py-1 text-xs font-bold rounded-full transition-colors ${getLinkedNodeStyle(key)}`,
|
|
5867
|
+
children: key
|
|
5868
|
+
}
|
|
5869
|
+
)
|
|
5870
|
+
] }, key)),
|
|
5871
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-orange-400 font-bold", children: "→" }),
|
|
5872
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-2 py-1 bg-gray-100 text-[10px] text-gray-600 rounded font-semibold", children: "TAIL" })
|
|
5873
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-gray-400 italic", children: "HEAD → TAIL (empty)" }) }),
|
|
5874
|
+
linkedOrder.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 pt-2 border-t border-orange-200 text-[10px] text-gray-500 text-center", children: "Doubly linked: each entry has prev/next pointers" })
|
|
5875
|
+
] })
|
|
5734
5876
|
] }),
|
|
5735
5877
|
accessOrder && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-4 p-3 bg-blue-50 rounded-lg", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs text-blue-700", children: [
|
|
5736
5878
|
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: "LRU Cache Usage:" }),
|
|
@@ -6437,7 +6579,7 @@ const ArrayDequeVisualizerComponent = ({
|
|
|
6437
6579
|
const isTail = index === tail;
|
|
6438
6580
|
const isHighlighted = index === highlightIndex;
|
|
6439
6581
|
const hasValue = array[index] !== null;
|
|
6440
|
-
let baseStyle = "border-2 transition-
|
|
6582
|
+
let baseStyle = "border-2 transition-colors duration-200 ";
|
|
6441
6583
|
if (resizing) {
|
|
6442
6584
|
baseStyle += "bg-yellow-100 border-yellow-400 ";
|
|
6443
6585
|
} else if (isHighlighted) {
|
|
@@ -6977,6 +7119,59 @@ const TreeSetVisualizerComponent = ({
|
|
|
6977
7119
|
] }) }),
|
|
6978
7120
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
6979
7121
|
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 400, className: showCode ? "flex-1" : "w-full", children: [
|
|
7122
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-emerald-50 to-teal-50 rounded-xl border-2 border-emerald-200", children: [
|
|
7123
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-emerald-800 mb-3 flex items-center gap-2", children: [
|
|
7124
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: "🌳" }),
|
|
7125
|
+
" Binary Search Tree Property"
|
|
7126
|
+
] }),
|
|
7127
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono text-sm bg-white rounded-lg p-3 border border-emerald-200", children: [
|
|
7128
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center text-emerald-700 font-bold text-base mb-2", children: [
|
|
7129
|
+
"left < ",
|
|
7130
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-800", children: "node" }),
|
|
7131
|
+
" < right"
|
|
7132
|
+
] }),
|
|
7133
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-gray-500 text-center", children: "All values in left subtree are smaller • All values in right subtree are larger" })
|
|
7134
|
+
] }),
|
|
7135
|
+
currentStepData.operation === "add" && currentStepData.value !== void 0 && currentNode !== void 0 && currentNode !== currentStepData.value && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 p-2 bg-white rounded-lg border border-emerald-200", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs text-center", children: [
|
|
7136
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold text-emerald-700", children: "Comparing:" }),
|
|
7137
|
+
" ",
|
|
7138
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-mono", children: [
|
|
7139
|
+
currentStepData.value,
|
|
7140
|
+
" ",
|
|
7141
|
+
currentStepData.value < currentNode ? "<" : ">",
|
|
7142
|
+
" ",
|
|
7143
|
+
currentNode
|
|
7144
|
+
] }),
|
|
7145
|
+
" → ",
|
|
7146
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: `font-bold ${currentStepData.value < currentNode ? "text-blue-600" : "text-orange-600"}`, children: [
|
|
7147
|
+
"Go ",
|
|
7148
|
+
currentStepData.value < currentNode ? "LEFT" : "RIGHT"
|
|
7149
|
+
] })
|
|
7150
|
+
] }) }),
|
|
7151
|
+
currentStepData.operation === "contains" && currentStepData.value !== void 0 && currentNode !== void 0 && !found && path.length > 0 && path[path.length - 1] !== currentStepData.value && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 p-2 bg-white rounded-lg border border-emerald-200", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs text-center", children: [
|
|
7152
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold text-emerald-700", children: "Comparing:" }),
|
|
7153
|
+
" ",
|
|
7154
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-mono", children: [
|
|
7155
|
+
currentStepData.value,
|
|
7156
|
+
" ",
|
|
7157
|
+
currentStepData.value < currentNode ? "<" : ">",
|
|
7158
|
+
" ",
|
|
7159
|
+
currentNode
|
|
7160
|
+
] }),
|
|
7161
|
+
" → ",
|
|
7162
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: `font-bold ${currentStepData.value < currentNode ? "text-blue-600" : "text-orange-600"}`, children: [
|
|
7163
|
+
"Go ",
|
|
7164
|
+
currentStepData.value < currentNode ? "LEFT" : "RIGHT"
|
|
7165
|
+
] })
|
|
7166
|
+
] }) }),
|
|
7167
|
+
found === true && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 p-2 bg-green-100 rounded-lg border border-green-300", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs text-center text-green-800 font-bold", children: [
|
|
7168
|
+
"✓ Found! ",
|
|
7169
|
+
currentStepData.value,
|
|
7170
|
+
" == ",
|
|
7171
|
+
currentNode
|
|
7172
|
+
] }) }),
|
|
7173
|
+
found === false && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 p-2 bg-red-100 rounded-lg border border-red-300", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-center text-red-800 font-bold", children: "✗ Not found! Reached null (no more children to check)" }) })
|
|
7174
|
+
] }),
|
|
6980
7175
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
|
|
6981
7176
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-gray-700 mb-2", children: "Binary Search Tree" }),
|
|
6982
7177
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-gray-50 rounded-lg p-2 overflow-x-auto", children: tree ? /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "300", height: "250", className: "mx-auto", children: renderTree(tree) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-32 flex items-center justify-center text-gray-400 text-sm", children: "Empty tree" }) })
|
|
@@ -7440,6 +7635,7 @@ const HEAP_CODE = [
|
|
|
7440
7635
|
const LEGEND_ITEMS$6 = [
|
|
7441
7636
|
{ color: "bg-purple-100", label: "Root (min)", border: "#c4b5fd" },
|
|
7442
7637
|
{ color: "bg-purple-500", label: "Active" },
|
|
7638
|
+
{ color: "bg-purple-200", label: "Sift Path", border: "#a78bfa" },
|
|
7443
7639
|
{ color: "bg-yellow-300", label: "Comparing" },
|
|
7444
7640
|
{ color: "bg-green-400", label: "Swapped" }
|
|
7445
7641
|
];
|
|
@@ -7456,6 +7652,15 @@ function generateHeapSteps() {
|
|
|
7456
7652
|
if (op === "offer" && value !== void 0) {
|
|
7457
7653
|
heap.push(value);
|
|
7458
7654
|
let idx = heap.length - 1;
|
|
7655
|
+
const getPathToRoot = (index) => {
|
|
7656
|
+
const path = [index];
|
|
7657
|
+
let i = index;
|
|
7658
|
+
while (i > 0) {
|
|
7659
|
+
i = Math.floor((i - 1) / 2);
|
|
7660
|
+
path.push(i);
|
|
7661
|
+
}
|
|
7662
|
+
return path;
|
|
7663
|
+
};
|
|
7459
7664
|
steps.push({
|
|
7460
7665
|
operation: "offer",
|
|
7461
7666
|
value,
|
|
@@ -7463,7 +7668,9 @@ function generateHeapSteps() {
|
|
|
7463
7668
|
description: `offer(${value}): Add to end of heap at index ${idx}`,
|
|
7464
7669
|
codeLine: 1,
|
|
7465
7670
|
variables: { value, index: idx },
|
|
7466
|
-
highlightIndex: idx
|
|
7671
|
+
highlightIndex: idx,
|
|
7672
|
+
siftPath: getPathToRoot(idx),
|
|
7673
|
+
currentIndex: idx
|
|
7467
7674
|
});
|
|
7468
7675
|
while (idx > 0) {
|
|
7469
7676
|
const parentIdx = Math.floor((idx - 1) / 2);
|
|
@@ -7478,7 +7685,9 @@ function generateHeapSteps() {
|
|
|
7478
7685
|
child: heap[idx],
|
|
7479
7686
|
parentVal: heap[parentIdx]
|
|
7480
7687
|
},
|
|
7481
|
-
compareIndices: [idx, parentIdx]
|
|
7688
|
+
compareIndices: [idx, parentIdx],
|
|
7689
|
+
siftPath: getPathToRoot(idx),
|
|
7690
|
+
currentIndex: idx
|
|
7482
7691
|
});
|
|
7483
7692
|
if (heap[idx] < heap[parentIdx]) {
|
|
7484
7693
|
[heap[idx], heap[parentIdx]] = [heap[parentIdx], heap[idx]];
|
|
@@ -7489,7 +7698,9 @@ function generateHeapSteps() {
|
|
|
7489
7698
|
codeLine: 8,
|
|
7490
7699
|
variables: { swapped: heap[parentIdx], index: parentIdx },
|
|
7491
7700
|
swapIndices: [idx, parentIdx],
|
|
7492
|
-
highlightIndex: parentIdx
|
|
7701
|
+
highlightIndex: parentIdx,
|
|
7702
|
+
siftPath: getPathToRoot(parentIdx),
|
|
7703
|
+
currentIndex: parentIdx
|
|
7493
7704
|
});
|
|
7494
7705
|
idx = parentIdx;
|
|
7495
7706
|
} else {
|
|
@@ -7499,7 +7710,9 @@ function generateHeapSteps() {
|
|
|
7499
7710
|
description: `siftUp: ${heap[idx]} >= ${heap[parentIdx]}, heap property satisfied!`,
|
|
7500
7711
|
codeLine: 7,
|
|
7501
7712
|
variables: { index: idx },
|
|
7502
|
-
highlightIndex: idx
|
|
7713
|
+
highlightIndex: idx,
|
|
7714
|
+
siftPath: getPathToRoot(idx),
|
|
7715
|
+
currentIndex: idx
|
|
7503
7716
|
});
|
|
7504
7717
|
break;
|
|
7505
7718
|
}
|
|
@@ -7509,6 +7722,21 @@ function generateHeapSteps() {
|
|
|
7509
7722
|
const removed = heap[0];
|
|
7510
7723
|
const last = heap.pop();
|
|
7511
7724
|
if (last === void 0) continue;
|
|
7725
|
+
const getPathToLeaf = (heapSize, startIdx) => {
|
|
7726
|
+
const path = [startIdx];
|
|
7727
|
+
let i = startIdx;
|
|
7728
|
+
while (2 * i + 1 < heapSize) {
|
|
7729
|
+
const left = 2 * i + 1;
|
|
7730
|
+
const right = 2 * i + 2;
|
|
7731
|
+
if (right < heapSize) {
|
|
7732
|
+
path.push(left, right);
|
|
7733
|
+
} else {
|
|
7734
|
+
path.push(left);
|
|
7735
|
+
}
|
|
7736
|
+
i = left;
|
|
7737
|
+
}
|
|
7738
|
+
return path;
|
|
7739
|
+
};
|
|
7512
7740
|
if (heap.length === 0) {
|
|
7513
7741
|
steps.push({
|
|
7514
7742
|
operation: "poll",
|
|
@@ -7528,7 +7756,9 @@ function generateHeapSteps() {
|
|
|
7528
7756
|
description: `poll(): Remove min ${removed}, move last element ${last} to root`,
|
|
7529
7757
|
codeLine: 13,
|
|
7530
7758
|
variables: { removed, moved: last },
|
|
7531
|
-
highlightIndex: 0
|
|
7759
|
+
highlightIndex: 0,
|
|
7760
|
+
siftPath: getPathToLeaf(heap.length, 0),
|
|
7761
|
+
currentIndex: 0
|
|
7532
7762
|
});
|
|
7533
7763
|
let idx = 0;
|
|
7534
7764
|
while (true) {
|
|
@@ -7548,7 +7778,8 @@ function generateHeapSteps() {
|
|
|
7548
7778
|
description: `siftDown: ${heap[idx]} is smaller than children, heap property satisfied!`,
|
|
7549
7779
|
codeLine: 14,
|
|
7550
7780
|
variables: { index: idx, value: heap[idx] },
|
|
7551
|
-
highlightIndex: idx
|
|
7781
|
+
highlightIndex: idx,
|
|
7782
|
+
currentIndex: idx
|
|
7552
7783
|
});
|
|
7553
7784
|
break;
|
|
7554
7785
|
}
|
|
@@ -7562,7 +7793,9 @@ function generateHeapSteps() {
|
|
|
7562
7793
|
child: heap[smallestIdx],
|
|
7563
7794
|
childIdx: smallestIdx
|
|
7564
7795
|
},
|
|
7565
|
-
compareIndices: [idx, smallestIdx]
|
|
7796
|
+
compareIndices: [idx, smallestIdx],
|
|
7797
|
+
siftPath: [idx, leftIdx < heap.length ? leftIdx : -1, rightIdx < heap.length ? rightIdx : -1].filter((i) => i >= 0),
|
|
7798
|
+
currentIndex: idx
|
|
7566
7799
|
});
|
|
7567
7800
|
[heap[idx], heap[smallestIdx]] = [heap[smallestIdx], heap[idx]];
|
|
7568
7801
|
steps.push({
|
|
@@ -7572,7 +7805,8 @@ function generateHeapSteps() {
|
|
|
7572
7805
|
codeLine: 14,
|
|
7573
7806
|
variables: { index: smallestIdx },
|
|
7574
7807
|
swapIndices: [idx, smallestIdx],
|
|
7575
|
-
highlightIndex: smallestIdx
|
|
7808
|
+
highlightIndex: smallestIdx,
|
|
7809
|
+
currentIndex: smallestIdx
|
|
7576
7810
|
});
|
|
7577
7811
|
idx = smallestIdx;
|
|
7578
7812
|
}
|
|
@@ -7698,7 +7932,7 @@ const PriorityQueueVisualizerComponent = ({ showControls = true, showCode = true
|
|
|
7698
7932
|
heap: [],
|
|
7699
7933
|
description: ""
|
|
7700
7934
|
};
|
|
7701
|
-
const { heap, highlightIndex, swapIndices, compareIndices, description } = currentStepData;
|
|
7935
|
+
const { heap, highlightIndex, swapIndices, compareIndices, description, siftPath, currentIndex } = currentStepData;
|
|
7702
7936
|
const positions = getTreePositions(heap.length);
|
|
7703
7937
|
const getNodeStyle = (idx) => {
|
|
7704
7938
|
if (idx === highlightIndex) {
|
|
@@ -7710,11 +7944,25 @@ const PriorityQueueVisualizerComponent = ({ showControls = true, showCode = true
|
|
|
7710
7944
|
if (compareIndices == null ? void 0 : compareIndices.includes(idx)) {
|
|
7711
7945
|
return "fill-yellow-300 stroke-yellow-400";
|
|
7712
7946
|
}
|
|
7947
|
+
if ((siftPath == null ? void 0 : siftPath.includes(idx)) && idx !== currentIndex) {
|
|
7948
|
+
return "fill-purple-200 stroke-purple-400";
|
|
7949
|
+
}
|
|
7713
7950
|
if (idx === 0) {
|
|
7714
7951
|
return "fill-purple-100 stroke-purple-300";
|
|
7715
7952
|
}
|
|
7716
7953
|
return "fill-white stroke-gray-300";
|
|
7717
7954
|
};
|
|
7955
|
+
const isEdgeOnPath = (parentIdx, childIdx) => {
|
|
7956
|
+
if (!siftPath || siftPath.length < 2) return false;
|
|
7957
|
+
for (let i = 0; i < siftPath.length - 1; i++) {
|
|
7958
|
+
const a = siftPath[i];
|
|
7959
|
+
const b = siftPath[i + 1];
|
|
7960
|
+
if (a === parentIdx && b === childIdx || a === childIdx && b === parentIdx) {
|
|
7961
|
+
return true;
|
|
7962
|
+
}
|
|
7963
|
+
}
|
|
7964
|
+
return false;
|
|
7965
|
+
};
|
|
7718
7966
|
const getTextColor = (idx) => {
|
|
7719
7967
|
if (idx === highlightIndex || (swapIndices == null ? void 0 : swapIndices.includes(idx))) {
|
|
7720
7968
|
return "white";
|
|
@@ -7735,6 +7983,49 @@ const PriorityQueueVisualizerComponent = ({ showControls = true, showCode = true
|
|
|
7735
7983
|
] }) }) }),
|
|
7736
7984
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
7737
7985
|
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 400, children: [
|
|
7986
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-purple-50 to-pink-50 rounded-xl border-2 border-purple-200", children: [
|
|
7987
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-purple-800 mb-3 flex items-center gap-2", children: [
|
|
7988
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: "🏔️" }),
|
|
7989
|
+
" Min-Heap Property"
|
|
7990
|
+
] }),
|
|
7991
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono text-sm bg-white rounded-lg p-3 border border-purple-200", children: [
|
|
7992
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-center text-purple-700 font-bold mb-2", children: "heap[parent] ≤ heap[children]" }),
|
|
7993
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-3 gap-2 text-xs text-gray-600", children: [
|
|
7994
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-purple-50 p-2 rounded text-center", children: [
|
|
7995
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold", children: "parent(i)" }),
|
|
7996
|
+
" = ⌊(i-1)/2⌋"
|
|
7997
|
+
] }),
|
|
7998
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-purple-50 p-2 rounded text-center", children: [
|
|
7999
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold", children: "left(i)" }),
|
|
8000
|
+
" = 2i + 1"
|
|
8001
|
+
] }),
|
|
8002
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-purple-50 p-2 rounded text-center", children: [
|
|
8003
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold", children: "right(i)" }),
|
|
8004
|
+
" = 2i + 2"
|
|
8005
|
+
] })
|
|
8006
|
+
] })
|
|
8007
|
+
] }),
|
|
8008
|
+
currentIndex !== void 0 && currentIndex >= 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 p-2 bg-white rounded-lg border border-purple-200", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs text-gray-600 text-center", children: [
|
|
8009
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-semibold text-purple-700", children: [
|
|
8010
|
+
"Current: i = ",
|
|
8011
|
+
currentIndex
|
|
8012
|
+
] }),
|
|
8013
|
+
currentIndex > 0 && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "mx-2", children: [
|
|
8014
|
+
"→ parent(",
|
|
8015
|
+
currentIndex,
|
|
8016
|
+
") = ⌊(",
|
|
8017
|
+
currentIndex,
|
|
8018
|
+
"-1)/2⌋ = ",
|
|
8019
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-purple-600 font-bold", children: Math.floor((currentIndex - 1) / 2) })
|
|
8020
|
+
] }),
|
|
8021
|
+
2 * currentIndex + 1 < heap.length && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "mx-2", children: [
|
|
8022
|
+
"→ left(",
|
|
8023
|
+
currentIndex,
|
|
8024
|
+
") = ",
|
|
8025
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-purple-600 font-bold", children: 2 * currentIndex + 1 })
|
|
8026
|
+
] })
|
|
8027
|
+
] }) })
|
|
8028
|
+
] }),
|
|
7738
8029
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
|
|
7739
8030
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-gray-700 mb-2", children: "Binary Heap Structure" }),
|
|
7740
8031
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-gray-50 rounded-lg p-2 overflow-x-auto", children: heap.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -7751,6 +8042,7 @@ const PriorityQueueVisualizerComponent = ({ showControls = true, showCode = true
|
|
|
7751
8042
|
const childPos = positions[idx];
|
|
7752
8043
|
if (!parentPos || !childPos) return null;
|
|
7753
8044
|
const isHighlighted = (compareIndices == null ? void 0 : compareIndices.includes(idx)) && (compareIndices == null ? void 0 : compareIndices.includes(parentIdx)) || (swapIndices == null ? void 0 : swapIndices.includes(idx)) && (swapIndices == null ? void 0 : swapIndices.includes(parentIdx));
|
|
8045
|
+
const isOnPath = isEdgeOnPath(parentIdx, idx);
|
|
7754
8046
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
7755
8047
|
"line",
|
|
7756
8048
|
{
|
|
@@ -7758,8 +8050,9 @@ const PriorityQueueVisualizerComponent = ({ showControls = true, showCode = true
|
|
|
7758
8050
|
y1: parentPos.y,
|
|
7759
8051
|
x2: childPos.x,
|
|
7760
8052
|
y2: childPos.y,
|
|
7761
|
-
stroke: isHighlighted ? "#a855f7" : "#d1d5db",
|
|
7762
|
-
strokeWidth: isHighlighted ? 2 : 1
|
|
8053
|
+
stroke: isHighlighted ? "#a855f7" : isOnPath ? "#c4b5fd" : "#d1d5db",
|
|
8054
|
+
strokeWidth: isHighlighted ? 3 : isOnPath ? 2 : 1,
|
|
8055
|
+
strokeDasharray: isOnPath && !isHighlighted ? "4,2" : void 0
|
|
7763
8056
|
},
|
|
7764
8057
|
`edge-${idx}`
|
|
7765
8058
|
);
|
|
@@ -7776,7 +8069,7 @@ const PriorityQueueVisualizerComponent = ({ showControls = true, showCode = true
|
|
|
7776
8069
|
"circle",
|
|
7777
8070
|
{
|
|
7778
8071
|
r: "18",
|
|
7779
|
-
className: `${getNodeStyle(idx)} stroke-2 transition-
|
|
8072
|
+
className: `${getNodeStyle(idx)} stroke-2 transition-colors`
|
|
7780
8073
|
}
|
|
7781
8074
|
),
|
|
7782
8075
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -8155,6 +8448,25 @@ const ConcurrentHashMapVisualizerComponent = ({ showControls = true, showCode =
|
|
|
8155
8448
|
] }) }),
|
|
8156
8449
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
8157
8450
|
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 350, children: [
|
|
8451
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-red-50 to-orange-50 rounded-xl border-2 border-red-200", children: [
|
|
8452
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-red-800 mb-3 flex items-center gap-2", children: [
|
|
8453
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: "⚡" }),
|
|
8454
|
+
" Why ConcurrentHashMap?"
|
|
8455
|
+
] }),
|
|
8456
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 text-xs", children: [
|
|
8457
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-red-100 p-2 rounded-lg border border-red-300", children: [
|
|
8458
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-bold text-red-700", children: "synchronized HashMap" }),
|
|
8459
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-red-600", children: "❌ Single lock for entire map" }),
|
|
8460
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-red-500", children: "All threads wait for one lock" })
|
|
8461
|
+
] }),
|
|
8462
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-green-100 p-2 rounded-lg border border-green-300", children: [
|
|
8463
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-bold text-green-700", children: "ConcurrentHashMap" }),
|
|
8464
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-green-600", children: "✓ Segment-level locking" }),
|
|
8465
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-green-500", children: "Threads work in parallel on different segments" })
|
|
8466
|
+
] })
|
|
8467
|
+
] }),
|
|
8468
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 text-[10px] text-gray-600 text-center", children: "get() never blocks • put() only locks one segment • Much better concurrency!" })
|
|
8469
|
+
] }),
|
|
8158
8470
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
|
|
8159
8471
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-gray-700 mb-2", children: "Segments (independent locks)" }),
|
|
8160
8472
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 gap-3", children: segments.map((seg, idx) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -8505,13 +8817,39 @@ const BlockingQueueVisualizerComponent = ({ showControls = true, showCode = true
|
|
|
8505
8817
|
] }) }) }),
|
|
8506
8818
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
8507
8819
|
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 350, children: [
|
|
8820
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-cyan-50 to-blue-50 rounded-xl border-2 border-cyan-200", children: [
|
|
8821
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-cyan-800 mb-3 flex items-center gap-2", children: [
|
|
8822
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: "🔄" }),
|
|
8823
|
+
" Producer-Consumer Pattern"
|
|
8824
|
+
] }),
|
|
8825
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-3 gap-2 text-xs", children: [
|
|
8826
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-green-100 p-2 rounded-lg border border-green-300 text-center", children: [
|
|
8827
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-bold text-green-700", children: "Producers" }),
|
|
8828
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-green-600", children: "put() → queue" }),
|
|
8829
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-green-500", children: "Block if FULL" })
|
|
8830
|
+
] }),
|
|
8831
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-gray-100 p-2 rounded-lg border border-gray-300 text-center", children: [
|
|
8832
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-bold text-gray-700", children: "BlockingQueue" }),
|
|
8833
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-600", children: "Thread-safe buffer" }),
|
|
8834
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-[10px] text-gray-500", children: [
|
|
8835
|
+
"Capacity: ",
|
|
8836
|
+
capacity
|
|
8837
|
+
] })
|
|
8838
|
+
] }),
|
|
8839
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-blue-100 p-2 rounded-lg border border-blue-300 text-center", children: [
|
|
8840
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-bold text-blue-700", children: "Consumers" }),
|
|
8841
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-blue-600", children: "take() ← queue" }),
|
|
8842
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-blue-500", children: "Block if EMPTY" })
|
|
8843
|
+
] })
|
|
8844
|
+
] })
|
|
8845
|
+
] }),
|
|
8508
8846
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-4 mb-4", children: [
|
|
8509
8847
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1", children: [
|
|
8510
8848
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs font-medium text-gray-500 mb-2 text-center", children: "Producers" }),
|
|
8511
8849
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: ["P1", "P2"].map((p) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
8512
8850
|
"div",
|
|
8513
8851
|
{
|
|
8514
|
-
className: `px-3 py-2 rounded-lg text-center text-sm font-medium transition-
|
|
8852
|
+
className: `px-3 py-2 rounded-lg text-center text-sm font-medium transition-colors ${activeThread === p ? "bg-green-500 text-white" : blockedProducers.includes(p) ? "bg-red-100 text-red-700 border-2 border-red-300" : "bg-green-100 text-green-700"}`,
|
|
8515
8853
|
children: [
|
|
8516
8854
|
p,
|
|
8517
8855
|
blockedProducers.includes(p) && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block text-[10px]", children: "BLOCKED" })
|
|
@@ -8532,7 +8870,7 @@ const BlockingQueueVisualizerComponent = ({ showControls = true, showCode = true
|
|
|
8532
8870
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-1", children: queue.length > 0 ? queue.map((item, idx) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
8533
8871
|
"div",
|
|
8534
8872
|
{
|
|
8535
|
-
className: `px-2 py-1.5 bg-white rounded border text-xs font-medium text-center transition-
|
|
8873
|
+
className: `px-2 py-1.5 bg-white rounded border text-xs font-medium text-center transition-colors ${idx === 0 ? "border-blue-300 bg-blue-50" : "border-gray-200"}`,
|
|
8536
8874
|
children: item.value
|
|
8537
8875
|
},
|
|
8538
8876
|
item.id
|
|
@@ -8540,7 +8878,7 @@ const BlockingQueueVisualizerComponent = ({ showControls = true, showCode = true
|
|
|
8540
8878
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 h-1.5 bg-gray-200 rounded-full overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8541
8879
|
"div",
|
|
8542
8880
|
{
|
|
8543
|
-
className: `h-full transition-
|
|
8881
|
+
className: `h-full transition-colors ${queue.length === capacity ? "bg-red-500" : "bg-cyan-500"}`,
|
|
8544
8882
|
style: { width: `${queue.length / capacity * 100}%` }
|
|
8545
8883
|
}
|
|
8546
8884
|
) })
|
|
@@ -8551,7 +8889,7 @@ const BlockingQueueVisualizerComponent = ({ showControls = true, showCode = true
|
|
|
8551
8889
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: ["C1", "C2"].map((c) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
8552
8890
|
"div",
|
|
8553
8891
|
{
|
|
8554
|
-
className: `px-3 py-2 rounded-lg text-center text-sm font-medium transition-
|
|
8892
|
+
className: `px-3 py-2 rounded-lg text-center text-sm font-medium transition-colors ${activeThread === c ? "bg-blue-500 text-white" : blockedConsumers.includes(c) ? "bg-red-100 text-red-700 border-2 border-red-300" : "bg-blue-100 text-blue-700"}`,
|
|
8555
8893
|
children: [
|
|
8556
8894
|
c,
|
|
8557
8895
|
blockedConsumers.includes(c) && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block text-[10px]", children: "BLOCKED" })
|
|
@@ -8835,7 +9173,7 @@ const CopyOnWriteVisualizerComponent = ({
|
|
|
8835
9173
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center gap-1", children: arr.map((item, idx) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
8836
9174
|
"div",
|
|
8837
9175
|
{
|
|
8838
|
-
className: `w-10 h-10 flex items-center justify-center rounded border-2 font-medium transition-
|
|
9176
|
+
className: `w-10 h-10 flex items-center justify-center rounded border-2 font-medium transition-colors ${isNew && idx === highlightIndex ? "bg-green-500 border-green-600 text-white" : isNew ? "bg-green-100 border-green-300 text-green-700" : "bg-gray-100 border-gray-300 text-gray-700"}`,
|
|
8839
9177
|
children: item
|
|
8840
9178
|
},
|
|
8841
9179
|
idx
|
|
@@ -8876,6 +9214,25 @@ const CopyOnWriteVisualizerComponent = ({
|
|
|
8876
9214
|
] }) }),
|
|
8877
9215
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
8878
9216
|
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 350, children: [
|
|
9217
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-lime-50 to-green-50 rounded-xl border-2 border-lime-200", children: [
|
|
9218
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-lime-800 mb-3 flex items-center gap-2", children: [
|
|
9219
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: "📋" }),
|
|
9220
|
+
" Copy-on-Write Pattern"
|
|
9221
|
+
] }),
|
|
9222
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 text-xs", children: [
|
|
9223
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-blue-100 p-2 rounded-lg border border-blue-300 text-center", children: [
|
|
9224
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-bold text-blue-700", children: "Read (get)" }),
|
|
9225
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-2xl text-blue-600", children: "O(1)" }),
|
|
9226
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-blue-500", children: "No lock, no copy" })
|
|
9227
|
+
] }),
|
|
9228
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-orange-100 p-2 rounded-lg border border-orange-300 text-center", children: [
|
|
9229
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-bold text-orange-700", children: "Write (add/set)" }),
|
|
9230
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-2xl text-orange-600", children: "O(n)" }),
|
|
9231
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-orange-500", children: "Full array copy" })
|
|
9232
|
+
] })
|
|
9233
|
+
] }),
|
|
9234
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 text-[10px] text-gray-600 text-center", children: "Best for: Read-heavy, rarely-modified collections • Iterators never throw ConcurrentModificationException" })
|
|
9235
|
+
] }),
|
|
8879
9236
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-4 p-4 bg-gray-50 rounded-lg", children: showCopy ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-4", children: [
|
|
8880
9237
|
renderArray(oldArray, "Old Array (readers use this)"),
|
|
8881
9238
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-2xl text-gray-400", children: "→" }),
|
|
@@ -9153,7 +9510,7 @@ const ImmutableCollectionsVisualizerComponent = ({ showControls = true, showCode
|
|
|
9153
9510
|
original.map((item, idx) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
9154
9511
|
"div",
|
|
9155
9512
|
{
|
|
9156
|
-
className: `w-12 h-12 flex items-center justify-center rounded-lg border-2 font-bold transition-
|
|
9513
|
+
className: `w-12 h-12 flex items-center justify-center rounded-lg border-2 font-bold transition-colors ${error ? "bg-red-100 border-red-300 text-red-700 animate-pulse" : "bg-violet-100 border-violet-300 text-violet-700"}`,
|
|
9157
9514
|
children: item
|
|
9158
9515
|
},
|
|
9159
9516
|
idx
|
|
@@ -9586,14 +9943,14 @@ const GCVisualizerComponent = ({
|
|
|
9586
9943
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9587
9944
|
"div",
|
|
9588
9945
|
{
|
|
9589
|
-
className: "absolute inset-y-0 left-0 bg-opacity-30 bg-gray-500 transition-
|
|
9946
|
+
className: "absolute inset-y-0 left-0 bg-opacity-30 bg-gray-500 transition-[width] duration-300",
|
|
9590
9947
|
style: { width: `${fillPercent}%` }
|
|
9591
9948
|
}
|
|
9592
9949
|
),
|
|
9593
9950
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 flex flex-wrap items-center gap-1 p-1", children: genObjects.map((obj) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9594
9951
|
"div",
|
|
9595
9952
|
{
|
|
9596
|
-
className: `px-1.5 py-0.5 text-[9px] font-medium rounded transition-
|
|
9953
|
+
className: `px-1.5 py-0.5 text-[9px] font-medium rounded transition-colors duration-200 ${getObjectStyle(obj)}`,
|
|
9597
9954
|
title: `${obj.id} (age: ${obj.age}, ${obj.reachable ? "reachable" : "garbage"})`,
|
|
9598
9955
|
children: [
|
|
9599
9956
|
obj.id.replace("obj", ""),
|
|
@@ -9651,6 +10008,28 @@ const GCVisualizerComponent = ({
|
|
|
9651
10008
|
] }) }),
|
|
9652
10009
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
9653
10010
|
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 400, className: showCode ? "flex-1" : "w-full", children: [
|
|
10011
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-purple-50 to-pink-50 rounded-xl border-2 border-purple-200", children: [
|
|
10012
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-purple-800 mb-3 flex items-center gap-2", children: [
|
|
10013
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: "🧬" }),
|
|
10014
|
+
" Generational Hypothesis"
|
|
10015
|
+
] }),
|
|
10016
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono text-sm bg-white rounded-lg p-3 border border-purple-200", children: [
|
|
10017
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-center text-purple-700 font-bold mb-2", children: '"Most objects die young"' }),
|
|
10018
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-gray-500 text-center", children: "~95% of objects become garbage before first GC • Optimize for the common case" })
|
|
10019
|
+
] }),
|
|
10020
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-3 grid grid-cols-2 gap-2 text-xs", children: [
|
|
10021
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-blue-100 p-2 rounded-lg border border-blue-300 text-center", children: [
|
|
10022
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-bold text-blue-700", children: "Young Gen" }),
|
|
10023
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-blue-600", children: "Fast copy collection" }),
|
|
10024
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-blue-500", children: "Minor GC (frequent)" })
|
|
10025
|
+
] }),
|
|
10026
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-amber-100 p-2 rounded-lg border border-amber-300 text-center", children: [
|
|
10027
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-bold text-amber-700", children: "Old Gen" }),
|
|
10028
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-amber-600", children: "Mark-sweep collection" }),
|
|
10029
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] text-amber-500", children: "Major GC (rare, slow)" })
|
|
10030
|
+
] })
|
|
10031
|
+
] })
|
|
10032
|
+
] }),
|
|
9654
10033
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
|
|
9655
10034
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-gray-700 mb-2", children: "JVM Heap Memory" }),
|
|
9656
10035
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-3 bg-blue-50 rounded-lg", children: [
|