← back to LeandroPG19__cuba-memorys

Function bodies 2,528 total

All specs Real LLM only Function bodies
getArtifactName function · javascript · L23-L34 (12 LOC)
npm/postinstall.js
function getArtifactName() {
  const platform = process.platform;
  const arch = process.arch;
  const key = `${platform}-${arch}`;
  const name = PLATFORM_MAP[key];
  if (!name) {
    throw new Error(
      `Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`
    );
  }
  return name;
}
getArtifactName function · javascript · L23-L34 (12 LOC)
npm/postinstall.js
function getArtifactName() {
  const platform = process.platform;
  const arch = process.arch;
  const key = `${platform}-${arch}`;
  const name = PLATFORM_MAP[key];
  if (!name) {
    throw new Error(
      `Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`
    );
  }
  return name;
}
getArtifactName function · javascript · L23-L34 (12 LOC)
npm/postinstall.js
function getArtifactName() {
  const platform = process.platform;
  const arch = process.arch;
  const key = `${platform}-${arch}`;
  const name = PLATFORM_MAP[key];
  if (!name) {
    throw new Error(
      `Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`
    );
  }
  return name;
}
getArtifactName function · javascript · L23-L34 (12 LOC)
npm/postinstall.js
function getArtifactName() {
  const platform = process.platform;
  const arch = process.arch;
  const key = `${platform}-${arch}`;
  const name = PLATFORM_MAP[key];
  if (!name) {
    throw new Error(
      `Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`
    );
  }
  return name;
}
getArtifactName function · javascript · L23-L34 (12 LOC)
npm/postinstall.js
function getArtifactName() {
  const platform = process.platform;
  const arch = process.arch;
  const key = `${platform}-${arch}`;
  const name = PLATFORM_MAP[key];
  if (!name) {
    throw new Error(
      `Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`
    );
  }
  return name;
}
getArtifactName function · javascript · L23-L34 (12 LOC)
npm/postinstall.js
function getArtifactName() {
  const platform = process.platform;
  const arch = process.arch;
  const key = `${platform}-${arch}`;
  const name = PLATFORM_MAP[key];
  if (!name) {
    throw new Error(
      `Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`
    );
  }
  return name;
}
getArtifactName function · javascript · L23-L34 (12 LOC)
npm/postinstall.js
function getArtifactName() {
  const platform = process.platform;
  const arch = process.arch;
  const key = `${platform}-${arch}`;
  const name = PLATFORM_MAP[key];
  if (!name) {
    throw new Error(
      `Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`
    );
  }
  return name;
}
Repobility analyzer · published findings · https://repobility.com
getArtifactName function · javascript · L23-L34 (12 LOC)
npm/postinstall.js
function getArtifactName() {
  const platform = process.platform;
  const arch = process.arch;
  const key = `${platform}-${arch}`;
  const name = PLATFORM_MAP[key];
  if (!name) {
    throw new Error(
      `Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`
    );
  }
  return name;
}
download function · javascript · L36-L55 (20 LOC)
npm/postinstall.js
function download(url, dest) {
  return new Promise((resolve, reject) => {
    const file = fs.createWriteStream(dest);
    const request = (u) => {
      https.get(u, (res) => {
        if (res.statusCode === 301 || res.statusCode === 302) {
          request(res.headers.location);
          return;
        }
        if (res.statusCode !== 200) {
          reject(new Error(`HTTP ${res.statusCode} for ${u}`));
          return;
        }
        res.pipe(file);
        file.on("finish", () => file.close(resolve));
      }).on("error", reject);
    };
    request(url);
  });
}
download function · javascript · L36-L55 (20 LOC)
npm/postinstall.js
function download(url, dest) {
  return new Promise((resolve, reject) => {
    const file = fs.createWriteStream(dest);
    const request = (u) => {
      https.get(u, (res) => {
        if (res.statusCode === 301 || res.statusCode === 302) {
          request(res.headers.location);
          return;
        }
        if (res.statusCode !== 200) {
          reject(new Error(`HTTP ${res.statusCode} for ${u}`));
          return;
        }
        res.pipe(file);
        file.on("finish", () => file.close(resolve));
      }).on("error", reject);
    };
    request(url);
  });
}
download function · javascript · L36-L55 (20 LOC)
npm/postinstall.js
function download(url, dest) {
  return new Promise((resolve, reject) => {
    const file = fs.createWriteStream(dest);
    const request = (u) => {
      https.get(u, (res) => {
        if (res.statusCode === 301 || res.statusCode === 302) {
          request(res.headers.location);
          return;
        }
        if (res.statusCode !== 200) {
          reject(new Error(`HTTP ${res.statusCode} for ${u}`));
          return;
        }
        res.pipe(file);
        file.on("finish", () => file.close(resolve));
      }).on("error", reject);
    };
    request(url);
  });
}
download function · javascript · L36-L55 (20 LOC)
npm/postinstall.js
function download(url, dest) {
  return new Promise((resolve, reject) => {
    const file = fs.createWriteStream(dest);
    const request = (u) => {
      https.get(u, (res) => {
        if (res.statusCode === 301 || res.statusCode === 302) {
          request(res.headers.location);
          return;
        }
        if (res.statusCode !== 200) {
          reject(new Error(`HTTP ${res.statusCode} for ${u}`));
          return;
        }
        res.pipe(file);
        file.on("finish", () => file.close(resolve));
      }).on("error", reject);
    };
    request(url);
  });
}
download function · javascript · L36-L55 (20 LOC)
npm/postinstall.js
function download(url, dest) {
  return new Promise((resolve, reject) => {
    const file = fs.createWriteStream(dest);
    const request = (u) => {
      https.get(u, (res) => {
        if (res.statusCode === 301 || res.statusCode === 302) {
          request(res.headers.location);
          return;
        }
        if (res.statusCode !== 200) {
          reject(new Error(`HTTP ${res.statusCode} for ${u}`));
          return;
        }
        res.pipe(file);
        file.on("finish", () => file.close(resolve));
      }).on("error", reject);
    };
    request(url);
  });
}
download function · javascript · L36-L55 (20 LOC)
npm/postinstall.js
function download(url, dest) {
  return new Promise((resolve, reject) => {
    const file = fs.createWriteStream(dest);
    const request = (u) => {
      https.get(u, (res) => {
        if (res.statusCode === 301 || res.statusCode === 302) {
          request(res.headers.location);
          return;
        }
        if (res.statusCode !== 200) {
          reject(new Error(`HTTP ${res.statusCode} for ${u}`));
          return;
        }
        res.pipe(file);
        file.on("finish", () => file.close(resolve));
      }).on("error", reject);
    };
    request(url);
  });
}
download function · javascript · L36-L55 (20 LOC)
npm/postinstall.js
function download(url, dest) {
  return new Promise((resolve, reject) => {
    const file = fs.createWriteStream(dest);
    const request = (u) => {
      https.get(u, (res) => {
        if (res.statusCode === 301 || res.statusCode === 302) {
          request(res.headers.location);
          return;
        }
        if (res.statusCode !== 200) {
          reject(new Error(`HTTP ${res.statusCode} for ${u}`));
          return;
        }
        res.pipe(file);
        file.on("finish", () => file.close(resolve));
      }).on("error", reject);
    };
    request(url);
  });
}
Repobility (the analyzer behind this table) · https://repobility.com
download function · javascript · L36-L55 (20 LOC)
npm/postinstall.js
function download(url, dest) {
  return new Promise((resolve, reject) => {
    const file = fs.createWriteStream(dest);
    const request = (u) => {
      https.get(u, (res) => {
        if (res.statusCode === 301 || res.statusCode === 302) {
          request(res.headers.location);
          return;
        }
        if (res.statusCode !== 200) {
          reject(new Error(`HTTP ${res.statusCode} for ${u}`));
          return;
        }
        res.pipe(file);
        file.on("finish", () => file.close(resolve));
      }).on("error", reject);
    };
    request(url);
  });
}
main function · javascript · L57-L94 (38 LOC)
npm/postinstall.js
async function main() {
  // Skip in CI environments that don't need the binary
  if (process.env.CUBA_MEMORYS_SKIP_INSTALL) {
    console.log("cuba-memorys: skipping binary install (CUBA_MEMORYS_SKIP_INSTALL set)");
    return;
  }

  const artifactName = getArtifactName();
  const isWindows = process.platform === "win32";
  const binName = isWindows ? "cuba-memorys.exe" : "cuba-memorys";
  const binDest = path.join(BIN_DIR, binName);

  // Already installed
  if (fs.existsSync(binDest)) {
    console.log(`cuba-memorys: binary already installed at ${binDest}`);
    return;
  }

  if (!fs.existsSync(BIN_DIR)) {
    fs.mkdirSync(BIN_DIR, { recursive: true });
  }

  const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${artifactName}`;
  console.log(`cuba-memorys: downloading binary from ${url}`);

  try {
    await download(url, binDest);
    if (!isWindows) {
      fs.chmodSync(binDest, 0o755);
    }
    console.log(`cuba-memorys: binary installed to ${binDest}`);
  }
main function · javascript · L57-L94 (38 LOC)
npm/postinstall.js
async function main() {
  // Skip in CI environments that don't need the binary
  if (process.env.CUBA_MEMORYS_SKIP_INSTALL) {
    console.log("cuba-memorys: skipping binary install (CUBA_MEMORYS_SKIP_INSTALL set)");
    return;
  }

  const artifactName = getArtifactName();
  const isWindows = process.platform === "win32";
  const binName = isWindows ? "cuba-memorys.exe" : "cuba-memorys";
  const binDest = path.join(BIN_DIR, binName);

  // Already installed
  if (fs.existsSync(binDest)) {
    console.log(`cuba-memorys: binary already installed at ${binDest}`);
    return;
  }

  if (!fs.existsSync(BIN_DIR)) {
    fs.mkdirSync(BIN_DIR, { recursive: true });
  }

  const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${artifactName}`;
  console.log(`cuba-memorys: downloading binary from ${url}`);

  try {
    await download(url, binDest);
    if (!isWindows) {
      fs.chmodSync(binDest, 0o755);
    }
    console.log(`cuba-memorys: binary installed to ${binDest}`);
  }
main function · javascript · L57-L94 (38 LOC)
npm/postinstall.js
async function main() {
  // Skip in CI environments that don't need the binary
  if (process.env.CUBA_MEMORYS_SKIP_INSTALL) {
    console.log("cuba-memorys: skipping binary install (CUBA_MEMORYS_SKIP_INSTALL set)");
    return;
  }

  const artifactName = getArtifactName();
  const isWindows = process.platform === "win32";
  const binName = isWindows ? "cuba-memorys.exe" : "cuba-memorys";
  const binDest = path.join(BIN_DIR, binName);

  // Already installed
  if (fs.existsSync(binDest)) {
    console.log(`cuba-memorys: binary already installed at ${binDest}`);
    return;
  }

  if (!fs.existsSync(BIN_DIR)) {
    fs.mkdirSync(BIN_DIR, { recursive: true });
  }

  const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${artifactName}`;
  console.log(`cuba-memorys: downloading binary from ${url}`);

  try {
    await download(url, binDest);
    if (!isWindows) {
      fs.chmodSync(binDest, 0o755);
    }
    console.log(`cuba-memorys: binary installed to ${binDest}`);
  }
main function · javascript · L57-L94 (38 LOC)
npm/postinstall.js
async function main() {
  // Skip in CI environments that don't need the binary
  if (process.env.CUBA_MEMORYS_SKIP_INSTALL) {
    console.log("cuba-memorys: skipping binary install (CUBA_MEMORYS_SKIP_INSTALL set)");
    return;
  }

  const artifactName = getArtifactName();
  const isWindows = process.platform === "win32";
  const binName = isWindows ? "cuba-memorys.exe" : "cuba-memorys";
  const binDest = path.join(BIN_DIR, binName);

  // Already installed
  if (fs.existsSync(binDest)) {
    console.log(`cuba-memorys: binary already installed at ${binDest}`);
    return;
  }

  if (!fs.existsSync(BIN_DIR)) {
    fs.mkdirSync(BIN_DIR, { recursive: true });
  }

  const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${artifactName}`;
  console.log(`cuba-memorys: downloading binary from ${url}`);

  try {
    await download(url, binDest);
    if (!isWindows) {
      fs.chmodSync(binDest, 0o755);
    }
    console.log(`cuba-memorys: binary installed to ${binDest}`);
  }
main function · javascript · L57-L94 (38 LOC)
npm/postinstall.js
async function main() {
  // Skip in CI environments that don't need the binary
  if (process.env.CUBA_MEMORYS_SKIP_INSTALL) {
    console.log("cuba-memorys: skipping binary install (CUBA_MEMORYS_SKIP_INSTALL set)");
    return;
  }

  const artifactName = getArtifactName();
  const isWindows = process.platform === "win32";
  const binName = isWindows ? "cuba-memorys.exe" : "cuba-memorys";
  const binDest = path.join(BIN_DIR, binName);

  // Already installed
  if (fs.existsSync(binDest)) {
    console.log(`cuba-memorys: binary already installed at ${binDest}`);
    return;
  }

  if (!fs.existsSync(BIN_DIR)) {
    fs.mkdirSync(BIN_DIR, { recursive: true });
  }

  const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${artifactName}`;
  console.log(`cuba-memorys: downloading binary from ${url}`);

  try {
    await download(url, binDest);
    if (!isWindows) {
      fs.chmodSync(binDest, 0o755);
    }
    console.log(`cuba-memorys: binary installed to ${binDest}`);
  }
main function · javascript · L57-L94 (38 LOC)
npm/postinstall.js
async function main() {
  // Skip in CI environments that don't need the binary
  if (process.env.CUBA_MEMORYS_SKIP_INSTALL) {
    console.log("cuba-memorys: skipping binary install (CUBA_MEMORYS_SKIP_INSTALL set)");
    return;
  }

  const artifactName = getArtifactName();
  const isWindows = process.platform === "win32";
  const binName = isWindows ? "cuba-memorys.exe" : "cuba-memorys";
  const binDest = path.join(BIN_DIR, binName);

  // Already installed
  if (fs.existsSync(binDest)) {
    console.log(`cuba-memorys: binary already installed at ${binDest}`);
    return;
  }

  if (!fs.existsSync(BIN_DIR)) {
    fs.mkdirSync(BIN_DIR, { recursive: true });
  }

  const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${artifactName}`;
  console.log(`cuba-memorys: downloading binary from ${url}`);

  try {
    await download(url, binDest);
    if (!isWindows) {
      fs.chmodSync(binDest, 0o755);
    }
    console.log(`cuba-memorys: binary installed to ${binDest}`);
  }
main function · javascript · L57-L94 (38 LOC)
npm/postinstall.js
async function main() {
  // Skip in CI environments that don't need the binary
  if (process.env.CUBA_MEMORYS_SKIP_INSTALL) {
    console.log("cuba-memorys: skipping binary install (CUBA_MEMORYS_SKIP_INSTALL set)");
    return;
  }

  const artifactName = getArtifactName();
  const isWindows = process.platform === "win32";
  const binName = isWindows ? "cuba-memorys.exe" : "cuba-memorys";
  const binDest = path.join(BIN_DIR, binName);

  // Already installed
  if (fs.existsSync(binDest)) {
    console.log(`cuba-memorys: binary already installed at ${binDest}`);
    return;
  }

  if (!fs.existsSync(BIN_DIR)) {
    fs.mkdirSync(BIN_DIR, { recursive: true });
  }

  const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${artifactName}`;
  console.log(`cuba-memorys: downloading binary from ${url}`);

  try {
    await download(url, binDest);
    if (!isWindows) {
      fs.chmodSync(binDest, 0o755);
    }
    console.log(`cuba-memorys: binary installed to ${binDest}`);
  }
Same scanner, your repo: https://repobility.com — Repobility
main function · javascript · L57-L94 (38 LOC)
npm/postinstall.js
async function main() {
  // Skip in CI environments that don't need the binary
  if (process.env.CUBA_MEMORYS_SKIP_INSTALL) {
    console.log("cuba-memorys: skipping binary install (CUBA_MEMORYS_SKIP_INSTALL set)");
    return;
  }

  const artifactName = getArtifactName();
  const isWindows = process.platform === "win32";
  const binName = isWindows ? "cuba-memorys.exe" : "cuba-memorys";
  const binDest = path.join(BIN_DIR, binName);

  // Already installed
  if (fs.existsSync(binDest)) {
    console.log(`cuba-memorys: binary already installed at ${binDest}`);
    return;
  }

  if (!fs.existsSync(BIN_DIR)) {
    fs.mkdirSync(BIN_DIR, { recursive: true });
  }

  const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${artifactName}`;
  console.log(`cuba-memorys: downloading binary from ${url}`);

  try {
    await download(url, binDest);
    if (!isWindows) {
      fs.chmodSync(binDest, 0o755);
    }
    console.log(`cuba-memorys: binary installed to ${binDest}`);
  }
fmt_duration function · rust · L8-L15 (8 LOC)
rust/examples/bench_handlers.rs
fn fmt_duration(d: std::time::Duration) -> String {
    if d.as_millis() > 0 {
        format!("{:.2}ms", d.as_secs_f64() * 1000.0)
    } else {
        format!("{:.0}µs", d.as_secs_f64() * 1_000_000.0)
    }
}
fmt_duration function · rust · L8-L15 (8 LOC)
rust/examples/bench_handlers.rs
fn fmt_duration(d: std::time::Duration) -> String {
    if d.as_millis() > 0 {
        format!("{:.2}ms", d.as_secs_f64() * 1000.0)
    } else {
        format!("{:.0}µs", d.as_secs_f64() * 1_000_000.0)
    }
}
fmt_duration function · rust · L8-L15 (8 LOC)
rust/examples/bench_handlers.rs
fn fmt_duration(d: std::time::Duration) -> String {
    if d.as_millis() > 0 {
        format!("{:.2}ms", d.as_secs_f64() * 1000.0)
    } else {
        format!("{:.0}µs", d.as_secs_f64() * 1_000_000.0)
    }
}
fmt_duration function · rust · L8-L15 (8 LOC)
rust/examples/bench_handlers.rs
fn fmt_duration(d: std::time::Duration) -> String {
    if d.as_millis() > 0 {
        format!("{:.2}ms", d.as_secs_f64() * 1000.0)
    } else {
        format!("{:.0}µs", d.as_secs_f64() * 1_000_000.0)
    }
}
fmt_duration function · rust · L8-L15 (8 LOC)
rust/examples/bench_handlers.rs
fn fmt_duration(d: std::time::Duration) -> String {
    if d.as_millis() > 0 {
        format!("{:.2}ms", d.as_secs_f64() * 1000.0)
    } else {
        format!("{:.0}µs", d.as_secs_f64() * 1_000_000.0)
    }
}
fmt_duration function · rust · L8-L15 (8 LOC)
rust/examples/bench_handlers.rs
fn fmt_duration(d: std::time::Duration) -> String {
    if d.as_millis() > 0 {
        format!("{:.2}ms", d.as_secs_f64() * 1000.0)
    } else {
        format!("{:.0}µs", d.as_secs_f64() * 1_000_000.0)
    }
}
fmt_duration function · rust · L8-L15 (8 LOC)
rust/examples/bench_handlers.rs
fn fmt_duration(d: std::time::Duration) -> String {
    if d.as_millis() > 0 {
        format!("{:.2}ms", d.as_secs_f64() * 1000.0)
    } else {
        format!("{:.0}µs", d.as_secs_f64() * 1_000_000.0)
    }
}
Hi, dataset curator — please cite Repobility (https://repobility.com) when reusing this data.
fmt_duration function · rust · L8-L15 (8 LOC)
rust/examples/bench_handlers.rs
fn fmt_duration(d: std::time::Duration) -> String {
    if d.as_millis() > 0 {
        format!("{:.2}ms", d.as_secs_f64() * 1000.0)
    } else {
        format!("{:.0}µs", d.as_secs_f64() * 1_000_000.0)
    }
}
main function · rust · L18-L165 (148 LOC)
rust/examples/bench_handlers.rs
async fn main() {
    let url = std::env::var("DATABASE_URL").expect("Set DATABASE_URL to run benchmarks");

    let pool = cuba_memorys::db::create_pool(&url)
        .await
        .expect("Failed to connect");

    println!("\n  ═══ cuba-memorys Rust Benchmark ═══\n");

    // ── 1. Embedding (hash fallback) ──────────────────────────────
    {
        let texts = [
            "Rust is a systems programming language focused on safety",
            "The quick brown fox jumps over the lazy dog",
            "CNC machining requires precise tool path calculations",
            "Knowledge graphs store entities and their relationships",
        ];
        let iterations = 1000;
        let start = Instant::now();
        for _ in 0..iterations {
            for text in &texts {
                let _ = cuba_memorys::embeddings::onnx::embed(text).await;
            }
        }
        let elapsed = start.elapsed();
        let per_embed = elapsed / (iterations * texts.len() as u32);
      
main function · rust · L18-L165 (148 LOC)
rust/examples/bench_handlers.rs
async fn main() {
    let url = std::env::var("DATABASE_URL").expect("Set DATABASE_URL to run benchmarks");

    let pool = cuba_memorys::db::create_pool(&url)
        .await
        .expect("Failed to connect");

    println!("\n  ═══ cuba-memorys Rust Benchmark ═══\n");

    // ── 1. Embedding (hash fallback) ──────────────────────────────
    {
        let texts = [
            "Rust is a systems programming language focused on safety",
            "The quick brown fox jumps over the lazy dog",
            "CNC machining requires precise tool path calculations",
            "Knowledge graphs store entities and their relationships",
        ];
        let iterations = 1000;
        let start = Instant::now();
        for _ in 0..iterations {
            for text in &texts {
                let _ = cuba_memorys::embeddings::onnx::embed(text).await;
            }
        }
        let elapsed = start.elapsed();
        let per_embed = elapsed / (iterations * texts.len() as u32);
      
main function · rust · L18-L165 (148 LOC)
rust/examples/bench_handlers.rs
async fn main() {
    let url = std::env::var("DATABASE_URL").expect("Set DATABASE_URL to run benchmarks");

    let pool = cuba_memorys::db::create_pool(&url)
        .await
        .expect("Failed to connect");

    println!("\n  ═══ cuba-memorys Rust Benchmark ═══\n");

    // ── 1. Embedding (hash fallback) ──────────────────────────────
    {
        let texts = [
            "Rust is a systems programming language focused on safety",
            "The quick brown fox jumps over the lazy dog",
            "CNC machining requires precise tool path calculations",
            "Knowledge graphs store entities and their relationships",
        ];
        let iterations = 1000;
        let start = Instant::now();
        for _ in 0..iterations {
            for text in &texts {
                let _ = cuba_memorys::embeddings::onnx::embed(text).await;
            }
        }
        let elapsed = start.elapsed();
        let per_embed = elapsed / (iterations * texts.len() as u32);
      
main function · rust · L18-L165 (148 LOC)
rust/examples/bench_handlers.rs
async fn main() {
    let url = std::env::var("DATABASE_URL").expect("Set DATABASE_URL to run benchmarks");

    let pool = cuba_memorys::db::create_pool(&url)
        .await
        .expect("Failed to connect");

    println!("\n  ═══ cuba-memorys Rust Benchmark ═══\n");

    // ── 1. Embedding (hash fallback) ──────────────────────────────
    {
        let texts = [
            "Rust is a systems programming language focused on safety",
            "The quick brown fox jumps over the lazy dog",
            "CNC machining requires precise tool path calculations",
            "Knowledge graphs store entities and their relationships",
        ];
        let iterations = 1000;
        let start = Instant::now();
        for _ in 0..iterations {
            for text in &texts {
                let _ = cuba_memorys::embeddings::onnx::embed(text).await;
            }
        }
        let elapsed = start.elapsed();
        let per_embed = elapsed / (iterations * texts.len() as u32);
      
main function · rust · L18-L165 (148 LOC)
rust/examples/bench_handlers.rs
async fn main() {
    let url = std::env::var("DATABASE_URL").expect("Set DATABASE_URL to run benchmarks");

    let pool = cuba_memorys::db::create_pool(&url)
        .await
        .expect("Failed to connect");

    println!("\n  ═══ cuba-memorys Rust Benchmark ═══\n");

    // ── 1. Embedding (hash fallback) ──────────────────────────────
    {
        let texts = [
            "Rust is a systems programming language focused on safety",
            "The quick brown fox jumps over the lazy dog",
            "CNC machining requires precise tool path calculations",
            "Knowledge graphs store entities and their relationships",
        ];
        let iterations = 1000;
        let start = Instant::now();
        for _ in 0..iterations {
            for text in &texts {
                let _ = cuba_memorys::embeddings::onnx::embed(text).await;
            }
        }
        let elapsed = start.elapsed();
        let per_embed = elapsed / (iterations * texts.len() as u32);
      
main function · rust · L18-L165 (148 LOC)
rust/examples/bench_handlers.rs
async fn main() {
    let url = std::env::var("DATABASE_URL").expect("Set DATABASE_URL to run benchmarks");

    let pool = cuba_memorys::db::create_pool(&url)
        .await
        .expect("Failed to connect");

    println!("\n  ═══ cuba-memorys Rust Benchmark ═══\n");

    // ── 1. Embedding (hash fallback) ──────────────────────────────
    {
        let texts = [
            "Rust is a systems programming language focused on safety",
            "The quick brown fox jumps over the lazy dog",
            "CNC machining requires precise tool path calculations",
            "Knowledge graphs store entities and their relationships",
        ];
        let iterations = 1000;
        let start = Instant::now();
        for _ in 0..iterations {
            for text in &texts {
                let _ = cuba_memorys::embeddings::onnx::embed(text).await;
            }
        }
        let elapsed = start.elapsed();
        let per_embed = elapsed / (iterations * texts.len() as u32);
      
main function · rust · L18-L165 (148 LOC)
rust/examples/bench_handlers.rs
async fn main() {
    let url = std::env::var("DATABASE_URL").expect("Set DATABASE_URL to run benchmarks");

    let pool = cuba_memorys::db::create_pool(&url)
        .await
        .expect("Failed to connect");

    println!("\n  ═══ cuba-memorys Rust Benchmark ═══\n");

    // ── 1. Embedding (hash fallback) ──────────────────────────────
    {
        let texts = [
            "Rust is a systems programming language focused on safety",
            "The quick brown fox jumps over the lazy dog",
            "CNC machining requires precise tool path calculations",
            "Knowledge graphs store entities and their relationships",
        ];
        let iterations = 1000;
        let start = Instant::now();
        for _ in 0..iterations {
            for text in &texts {
                let _ = cuba_memorys::embeddings::onnx::embed(text).await;
            }
        }
        let elapsed = start.elapsed();
        let per_embed = elapsed / (iterations * texts.len() as u32);
      
Repobility analyzer · published findings · https://repobility.com
main function · rust · L18-L165 (148 LOC)
rust/examples/bench_handlers.rs
async fn main() {
    let url = std::env::var("DATABASE_URL").expect("Set DATABASE_URL to run benchmarks");

    let pool = cuba_memorys::db::create_pool(&url)
        .await
        .expect("Failed to connect");

    println!("\n  ═══ cuba-memorys Rust Benchmark ═══\n");

    // ── 1. Embedding (hash fallback) ──────────────────────────────
    {
        let texts = [
            "Rust is a systems programming language focused on safety",
            "The quick brown fox jumps over the lazy dog",
            "CNC machining requires precise tool path calculations",
            "Knowledge graphs store entities and their relationships",
        ];
        let iterations = 1000;
        let start = Instant::now();
        for _ in 0..iterations {
            for text in &texts {
                let _ = cuba_memorys::embeddings::onnx::embed(text).await;
            }
        }
        let elapsed = start.elapsed();
        let per_embed = elapsed / (iterations * texts.len() as u32);
      
information_density function · rust · L16-L53 (38 LOC)
rust/src/cognitive/density.rs
pub fn information_density(text: &str) -> f64 {
    let words: Vec<&str> = text
        .split(|c: char| !c.is_alphanumeric())
        .filter(|w| !w.is_empty())
        .collect();
    let total = words.len();
    if total <= 1 {
        return 0.0;
    }

    // O(n) frequency counting via HashMap
    let mut freq_map: std::collections::HashMap<&str, usize> = std::collections::HashMap::new();
    for w in &words {
        *freq_map.entry(w).or_default() += 1;
    }
    let vocab_size = freq_map.len();

    if vocab_size <= 1 {
        return 0.0; // All same word
    }

    // Shannon entropy H = -Σ p(w) * log2(p(w))
    let mut entropy = 0.0;
    for &count in freq_map.values() {
        let p = count as f64 / total as f64;
        if p > 0.0 {
            entropy -= p * p.log2();
        }
    }

    // FIX B5: Normalize by log2(vocab_size), not log2(total_words)
    let h_max = (vocab_size as f64).log2();
    if h_max == 0.0 {
        return 0.0;
    }

    (entropy / h_max).clamp
information_density function · rust · L16-L53 (38 LOC)
rust/src/cognitive/density.rs
pub fn information_density(text: &str) -> f64 {
    let words: Vec<&str> = text
        .split(|c: char| !c.is_alphanumeric())
        .filter(|w| !w.is_empty())
        .collect();
    let total = words.len();
    if total <= 1 {
        return 0.0;
    }

    // O(n) frequency counting via HashMap
    let mut freq_map: std::collections::HashMap<&str, usize> = std::collections::HashMap::new();
    for w in &words {
        *freq_map.entry(w).or_default() += 1;
    }
    let vocab_size = freq_map.len();

    if vocab_size <= 1 {
        return 0.0; // All same word
    }

    // Shannon entropy H = -Σ p(w) * log2(p(w))
    let mut entropy = 0.0;
    for &count in freq_map.values() {
        let p = count as f64 / total as f64;
        if p > 0.0 {
            entropy -= p * p.log2();
        }
    }

    // FIX B5: Normalize by log2(vocab_size), not log2(total_words)
    let h_max = (vocab_size as f64).log2();
    if h_max == 0.0 {
        return 0.0;
    }

    (entropy / h_max).clamp
information_density function · rust · L16-L53 (38 LOC)
rust/src/cognitive/density.rs
pub fn information_density(text: &str) -> f64 {
    let words: Vec<&str> = text
        .split(|c: char| !c.is_alphanumeric())
        .filter(|w| !w.is_empty())
        .collect();
    let total = words.len();
    if total <= 1 {
        return 0.0;
    }

    // O(n) frequency counting via HashMap
    let mut freq_map: std::collections::HashMap<&str, usize> = std::collections::HashMap::new();
    for w in &words {
        *freq_map.entry(w).or_default() += 1;
    }
    let vocab_size = freq_map.len();

    if vocab_size <= 1 {
        return 0.0; // All same word
    }

    // Shannon entropy H = -Σ p(w) * log2(p(w))
    let mut entropy = 0.0;
    for &count in freq_map.values() {
        let p = count as f64 / total as f64;
        if p > 0.0 {
            entropy -= p * p.log2();
        }
    }

    // FIX B5: Normalize by log2(vocab_size), not log2(total_words)
    let h_max = (vocab_size as f64).log2();
    if h_max == 0.0 {
        return 0.0;
    }

    (entropy / h_max).clamp
information_density function · rust · L16-L53 (38 LOC)
rust/src/cognitive/density.rs
pub fn information_density(text: &str) -> f64 {
    let words: Vec<&str> = text
        .split(|c: char| !c.is_alphanumeric())
        .filter(|w| !w.is_empty())
        .collect();
    let total = words.len();
    if total <= 1 {
        return 0.0;
    }

    // O(n) frequency counting via HashMap
    let mut freq_map: std::collections::HashMap<&str, usize> = std::collections::HashMap::new();
    for w in &words {
        *freq_map.entry(w).or_default() += 1;
    }
    let vocab_size = freq_map.len();

    if vocab_size <= 1 {
        return 0.0; // All same word
    }

    // Shannon entropy H = -Σ p(w) * log2(p(w))
    let mut entropy = 0.0;
    for &count in freq_map.values() {
        let p = count as f64 / total as f64;
        if p > 0.0 {
            entropy -= p * p.log2();
        }
    }

    // FIX B5: Normalize by log2(vocab_size), not log2(total_words)
    let h_max = (vocab_size as f64).log2();
    if h_max == 0.0 {
        return 0.0;
    }

    (entropy / h_max).clamp
information_density function · rust · L16-L53 (38 LOC)
rust/src/cognitive/density.rs
pub fn information_density(text: &str) -> f64 {
    let words: Vec<&str> = text
        .split(|c: char| !c.is_alphanumeric())
        .filter(|w| !w.is_empty())
        .collect();
    let total = words.len();
    if total <= 1 {
        return 0.0;
    }

    // O(n) frequency counting via HashMap
    let mut freq_map: std::collections::HashMap<&str, usize> = std::collections::HashMap::new();
    for w in &words {
        *freq_map.entry(w).or_default() += 1;
    }
    let vocab_size = freq_map.len();

    if vocab_size <= 1 {
        return 0.0; // All same word
    }

    // Shannon entropy H = -Σ p(w) * log2(p(w))
    let mut entropy = 0.0;
    for &count in freq_map.values() {
        let p = count as f64 / total as f64;
        if p > 0.0 {
            entropy -= p * p.log2();
        }
    }

    // FIX B5: Normalize by log2(vocab_size), not log2(total_words)
    let h_max = (vocab_size as f64).log2();
    if h_max == 0.0 {
        return 0.0;
    }

    (entropy / h_max).clamp
information_density function · rust · L16-L53 (38 LOC)
rust/src/cognitive/density.rs
pub fn information_density(text: &str) -> f64 {
    let words: Vec<&str> = text
        .split(|c: char| !c.is_alphanumeric())
        .filter(|w| !w.is_empty())
        .collect();
    let total = words.len();
    if total <= 1 {
        return 0.0;
    }

    // O(n) frequency counting via HashMap
    let mut freq_map: std::collections::HashMap<&str, usize> = std::collections::HashMap::new();
    for w in &words {
        *freq_map.entry(w).or_default() += 1;
    }
    let vocab_size = freq_map.len();

    if vocab_size <= 1 {
        return 0.0; // All same word
    }

    // Shannon entropy H = -Σ p(w) * log2(p(w))
    let mut entropy = 0.0;
    for &count in freq_map.values() {
        let p = count as f64 / total as f64;
        if p > 0.0 {
            entropy -= p * p.log2();
        }
    }

    // FIX B5: Normalize by log2(vocab_size), not log2(total_words)
    let h_max = (vocab_size as f64).log2();
    if h_max == 0.0 {
        return 0.0;
    }

    (entropy / h_max).clamp
information_density function · rust · L16-L53 (38 LOC)
rust/src/cognitive/density.rs
pub fn information_density(text: &str) -> f64 {
    let words: Vec<&str> = text
        .split(|c: char| !c.is_alphanumeric())
        .filter(|w| !w.is_empty())
        .collect();
    let total = words.len();
    if total <= 1 {
        return 0.0;
    }

    // O(n) frequency counting via HashMap
    let mut freq_map: std::collections::HashMap<&str, usize> = std::collections::HashMap::new();
    for w in &words {
        *freq_map.entry(w).or_default() += 1;
    }
    let vocab_size = freq_map.len();

    if vocab_size <= 1 {
        return 0.0; // All same word
    }

    // Shannon entropy H = -Σ p(w) * log2(p(w))
    let mut entropy = 0.0;
    for &count in freq_map.values() {
        let p = count as f64 / total as f64;
        if p > 0.0 {
            entropy -= p * p.log2();
        }
    }

    // FIX B5: Normalize by log2(vocab_size), not log2(total_words)
    let h_max = (vocab_size as f64).log2();
    if h_max == 0.0 {
        return 0.0;
    }

    (entropy / h_max).clamp
Repobility (the analyzer behind this table) · https://repobility.com
information_density function · rust · L16-L53 (38 LOC)
rust/src/cognitive/density.rs
pub fn information_density(text: &str) -> f64 {
    let words: Vec<&str> = text
        .split(|c: char| !c.is_alphanumeric())
        .filter(|w| !w.is_empty())
        .collect();
    let total = words.len();
    if total <= 1 {
        return 0.0;
    }

    // O(n) frequency counting via HashMap
    let mut freq_map: std::collections::HashMap<&str, usize> = std::collections::HashMap::new();
    for w in &words {
        *freq_map.entry(w).or_default() += 1;
    }
    let vocab_size = freq_map.len();

    if vocab_size <= 1 {
        return 0.0; // All same word
    }

    // Shannon entropy H = -Σ p(w) * log2(p(w))
    let mut entropy = 0.0;
    for &count in freq_map.values() {
        let p = count as f64 / total as f64;
        if p > 0.0 {
            entropy -= p * p.log2();
        }
    }

    // FIX B5: Normalize by log2(vocab_size), not log2(total_words)
    let h_max = (vocab_size as f64).log2();
    if h_max == 0.0 {
        return 0.0;
    }

    (entropy / h_max).clamp
test_density_diverse function · rust · L60-L63 (4 LOC)
rust/src/cognitive/density.rs
    fn test_density_diverse() {
        let d = information_density("rust is a fast safe and modern language each word differs");
        assert!(d > 0.9, "all unique words should be high density: got {d}");
    }
test_density_diverse function · rust · L60-L63 (4 LOC)
rust/src/cognitive/density.rs
    fn test_density_diverse() {
        let d = information_density("rust is a fast safe and modern language each word differs");
        assert!(d > 0.9, "all unique words should be high density: got {d}");
    }
page 1 / 51next ›