@tomaszjarosz/react-visualizers 0.2.2 → 0.2.4

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 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
- description: `Resize! Array full (${oldCapacity}/${oldCapacity}). Create new array with capacity ${capacity}, copy elements → O(n)`,
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: 350, className: showCode ? "flex-1" : "w-full", children: [
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-all ${getCellStyle(idx)}`,
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
  ),
@@ -7227,7 +7276,7 @@ const EnumSetVisualizerComponent = ({
7227
7276
  /* @__PURE__ */ jsxRuntime.jsxs(
7228
7277
  "div",
7229
7278
  {
7230
- className: `w-14 h-10 flex flex-col items-center justify-center text-xs font-medium rounded transition-all duration-200 ${getBitStyle(idx)}`,
7279
+ className: `w-14 h-10 flex flex-col items-center justify-center text-xs font-medium rounded transition-colors duration-200 ${getBitStyle(idx)}`,
7231
7280
  children: [
7232
7281
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-[10px] opacity-80", children: [
7233
7282
  "bit ",
@@ -7293,27 +7342,27 @@ const EnumSetVisualizerComponent = ({
7293
7342
  bitmask === 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-gray-400 italic", children: "Empty set" })
7294
7343
  ] })
7295
7344
  ] }),
7296
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-4 p-3 bg-blue-50 rounded-lg", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs text-gray-700", children: [
7297
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold text-blue-700", children: "vs HashSet:" }),
7298
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-1 grid grid-cols-2 gap-2 text-[10px]", children: [
7299
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7300
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-green-600", children: "EnumSet:" }),
7301
- " 1 long = 8 bytes"
7302
- ] }),
7303
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7304
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-500", children: "HashSet:" }),
7305
- " ~40+ bytes per entry"
7306
- ] }),
7307
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7308
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-green-600", children: "EnumSet:" }),
7309
- " O(1) bit operation"
7345
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-green-50 to-lime-50 rounded-xl border-2 border-green-200", children: [
7346
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-bold text-green-800 mb-3 flex items-center gap-2", children: [
7347
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: "💡" }),
7348
+ " Why EnumSet? Memory Efficiency!"
7349
+ ] }),
7350
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
7351
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-white p-3 rounded-lg border-2 border-green-300", children: [
7352
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-bold text-green-700 mb-2", children: "EnumSet" }),
7353
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-2xl font-bold text-green-600 mb-1", children: "8 bytes" }),
7354
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-gray-600", children: "1 long for up to 64 enum values" }),
7355
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 text-xs text-green-600", children: "✓ Single CPU instruction per operation" })
7310
7356
  ] }),
7311
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7312
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-500", children: "HashSet:" }),
7313
- " O(1) with hash overhead"
7357
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-white p-3 rounded-lg border-2 border-gray-300", children: [
7358
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-bold text-gray-500 mb-2", children: "HashSet" }),
7359
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-2xl font-bold text-gray-500 mb-1", children: "~280 bytes" }),
7360
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-gray-500", children: "For 7 enum values (~40 bytes each)" }),
7361
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 text-xs text-gray-500", children: "Hash computation + object overhead" })
7314
7362
  ] })
7315
- ] })
7316
- ] }) }),
7363
+ ] }),
7364
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 text-center", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "inline-block px-3 py-1 bg-green-100 text-green-800 rounded-full text-sm font-bold", children: "35x smaller memory footprint!" }) })
7365
+ ] }),
7317
7366
  /* @__PURE__ */ jsxRuntime.jsx(
7318
7367
  StatusPanel,
7319
7368
  {