@tomaszjarosz/react-visualizers 0.2.2 → 0.2.3
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/index.cjs +53 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +53 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5841,6 +5841,7 @@ function generateArrayListSteps() {
|
|
|
5841
5841
|
if (op === "add" && value !== void 0) {
|
|
5842
5842
|
if (size === capacity) {
|
|
5843
5843
|
const oldCapacity = capacity;
|
|
5844
|
+
const oldArray = [...array];
|
|
5844
5845
|
capacity *= 2;
|
|
5845
5846
|
const newArray = new Array(capacity).fill(null);
|
|
5846
5847
|
for (let i = 0; i < size; i++) {
|
|
@@ -5850,9 +5851,11 @@ function generateArrayListSteps() {
|
|
|
5850
5851
|
steps.push({
|
|
5851
5852
|
operation: "resize",
|
|
5852
5853
|
array: [...array],
|
|
5854
|
+
oldArray,
|
|
5853
5855
|
size,
|
|
5854
5856
|
capacity,
|
|
5855
|
-
|
|
5857
|
+
oldCapacity,
|
|
5858
|
+
description: `Resize! Array full (${oldCapacity}/${oldCapacity}). Create new array with capacity ${capacity}, copy ${size} elements → O(n)`,
|
|
5856
5859
|
codeLine: 2,
|
|
5857
5860
|
variables: { oldCapacity, newCapacity: capacity, copied: size }
|
|
5858
5861
|
});
|
|
@@ -5982,7 +5985,7 @@ const ArrayListVisualizerComponent = ({
|
|
|
5982
5985
|
capacity: INITIAL_CAPACITY$1,
|
|
5983
5986
|
description: ""
|
|
5984
5987
|
};
|
|
5985
|
-
const { array, size, capacity, highlightIndex, shiftIndices, description } = stepData;
|
|
5988
|
+
const { array, size, capacity, highlightIndex, shiftIndices, description, oldArray, oldCapacity, operation } = stepData;
|
|
5986
5989
|
const getCellStyle = (idx) => {
|
|
5987
5990
|
if (idx === highlightIndex) {
|
|
5988
5991
|
return "bg-orange-500 border-orange-600 text-white";
|
|
@@ -6020,7 +6023,53 @@ const ArrayListVisualizerComponent = ({
|
|
|
6020
6023
|
/* @__PURE__ */ jsxRuntime.jsx(ShareButton, { onShare: handleShare })
|
|
6021
6024
|
] }) }),
|
|
6022
6025
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
6023
|
-
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight:
|
|
6026
|
+
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 400, className: showCode ? "flex-1" : "w-full", children: [
|
|
6027
|
+
operation === "resize" && oldArray && /* @__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: [
|
|
6028
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-red-700 mb-3 flex items-center gap-2", children: [
|
|
6029
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xl", children: "⚠️" }),
|
|
6030
|
+
" RESIZE OPERATION (O(n) cost!)"
|
|
6031
|
+
] }),
|
|
6032
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
|
|
6033
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
6034
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs font-medium text-gray-600 mb-2", children: [
|
|
6035
|
+
"OLD Array (capacity: ",
|
|
6036
|
+
oldCapacity,
|
|
6037
|
+
") - FULL!"
|
|
6038
|
+
] }),
|
|
6039
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-white rounded-lg p-2 border border-red-200", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1 flex-wrap", children: oldArray.map((val, idx) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
6040
|
+
"div",
|
|
6041
|
+
{
|
|
6042
|
+
className: "w-10 h-10 flex items-center justify-center rounded border-2 text-sm font-medium bg-red-100 border-red-300 text-red-800",
|
|
6043
|
+
children: val !== null ? val : ""
|
|
6044
|
+
},
|
|
6045
|
+
idx
|
|
6046
|
+
)) }) })
|
|
6047
|
+
] }),
|
|
6048
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "hidden md:flex items-center justify-center absolute left-1/2 -translate-x-1/2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-2xl text-orange-500", children: "→" }) }),
|
|
6049
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
6050
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs font-medium text-gray-600 mb-2", children: [
|
|
6051
|
+
"NEW Array (capacity: ",
|
|
6052
|
+
capacity,
|
|
6053
|
+
") - 2x bigger"
|
|
6054
|
+
] }),
|
|
6055
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-white rounded-lg p-2 border border-green-200", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1 flex-wrap", children: array.map((val, idx) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
6056
|
+
"div",
|
|
6057
|
+
{
|
|
6058
|
+
className: `w-10 h-10 flex items-center justify-center rounded border-2 text-sm font-medium ${idx < size ? "bg-green-100 border-green-300 text-green-800" : "bg-gray-100 border-gray-200 text-gray-300"}`,
|
|
6059
|
+
children: val !== null ? val : ""
|
|
6060
|
+
},
|
|
6061
|
+
idx
|
|
6062
|
+
)) }) })
|
|
6063
|
+
] })
|
|
6064
|
+
] }),
|
|
6065
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-3 text-xs text-red-600 text-center", children: [
|
|
6066
|
+
"All ",
|
|
6067
|
+
size,
|
|
6068
|
+
" elements copied to new array → This is why add() is O(1) ",
|
|
6069
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: "amortized" }),
|
|
6070
|
+
", not O(1)"
|
|
6071
|
+
] })
|
|
6072
|
+
] }),
|
|
6024
6073
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
|
|
6025
6074
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-medium text-gray-700 mb-2", children: [
|
|
6026
6075
|
"Internal Array (capacity: ",
|
|
@@ -6031,7 +6080,7 @@ const ArrayListVisualizerComponent = ({
|
|
|
6031
6080
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6032
6081
|
"div",
|
|
6033
6082
|
{
|
|
6034
|
-
className: `w-12 h-12 flex items-center justify-center rounded border-2 font-medium transition-
|
|
6083
|
+
className: `w-12 h-12 flex items-center justify-center rounded border-2 font-medium transition-colors ${getCellStyle(idx)}`,
|
|
6035
6084
|
children: val !== null ? val : ""
|
|
6036
6085
|
}
|
|
6037
6086
|
),
|