CodeSampleX

サンプル

litemap 0.8.3

検証済みサンプル — cargo litemap 0.8.3. rust 1 · linux alpine/x64 · docker で contract を実行し、成功しました: LiteMap creates empty vector-backed map and reports length…

sha256:b04e14e60b1dfeba6f6a529986e9fc32594093b8ceb63f934d7a54f2e7440f77

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux · alpine · musl x64 cargo

検証実行環境

環境 コントラクト ステージ 実行日
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-09-19

ケース

HOW
ゴール
verify pkg:cargo/litemap@0.8.3
パッケージ
作成日
2026-09-18T13:35:13Z

コントラクト

  1. LiteMap creates empty vector-backed map and reports length, emptiness, and capacity
  2. LiteMap inserts key-value pairs maintaining sorted order and replaces existing keys returning previous value
  3. LiteMap retrieves values by key reference, supports contains_key, and provides mutable access via get_mut
  4. LiteMap removes entries by key, supports try_insert and try_append preserving sort invariants, and clears elements
  5. LiteMap provides entry API for in-place vacant and occupied entry manipulation

ファイル

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

ソースアーティファクトをダウンロード (tar.gz)

ソース

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "litemap"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae"

[[package]]
name = "sample-litemap"
version = "1.0.0"
dependencies = [
 "litemap",
]
Cargo.toml
[package]
name = "sample-litemap"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
litemap = "=0.8.3"

[[bin]]
name = "contract"
path = "test/contract.rs"
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:cargo/litemap@0.8.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/litemap@0.8.3

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:cd3ae638056cd0d28f5a5c1bd81f28f050778206b56901beb3bc291c23dd655e","contract":["LiteMap creates empty vector-backed map and reports length, emptiness, and capacity","LiteMap inserts key-value pairs maintaining sorted order and replaces existing keys returning previous value","LiteMap retrieves values by key reference, supports contains_key, and provides mutable access via get_mut","LiteMap removes entries by key, supports try_insert and try_append preserving sort invariants, and clears elements","LiteMap provides entry API for in-place vacant and occupied entry manipulation"],"goal":"verify pkg:cargo/litemap@0.8.3","kind":"HOW","packages":["pkg:cargo/litemap@0.8.3"],"schemaVersion":1},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/litemap@0.8.3"],"schemaVersion":1,"subject":"pkg:cargo/litemap@0.8.3","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/litemap@0.8.3",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/litemap@0.8.3"
  ]
}
src/lib.rs
//! Clean-room verification sample for litemap.

pub use litemap::*;
test/contract.rs
use litemap::{Entry, LiteMap};

fn main() {
    // 1. LiteMap creates empty vector-backed map and reports length, emptiness, and capacity
    let mut map: LiteMap<i32, &str> = LiteMap::new_vec();
    assert!(map.is_empty());
    assert_eq!(map.len(), 0);
    assert_eq!(map.first(), None);
    assert_eq!(map.last(), None);

    let mut cap_map: LiteMap<i32, &str> = LiteMap::with_capacity(10);
    assert!(cap_map.is_empty());
    assert_eq!(cap_map.len(), 0);
    cap_map.reserve(5);

    // 2. LiteMap inserts key-value pairs maintaining sorted order and replaces existing keys returning previous value
    assert_eq!(map.insert(30, "thirty"), None);
    assert_eq!(map.insert(10, "ten"), None);
    assert_eq!(map.insert(20, "twenty"), None);
    assert_eq!(map.len(), 3);
    assert!(!map.is_empty());

    // Sorted order: 10, 20, 30
    assert_eq!(map.first(), Some((&10, &"ten")));
    assert_eq!(map.last(), Some((&30, &"thirty")));
    assert_eq!(map.get_indexed(1), Some((&20, &"twenty")));

    // Replace existing key
    let old = map.insert(20, "twenty-updated");
    assert_eq!(old, Some("twenty"));
    assert_eq!(map.get(&20), Some(&"twenty-updated"));
    assert_eq!(map.len(), 3);

    // 3. LiteMap retrieves values by key reference, supports contains_key, and provides mutable access via get_mut
    assert!(map.contains_key(&10));
    assert!(map.contains_key(&20));
    assert!(map.contains_key(&30));
    assert!(!map.contains_key(&40));

    assert_eq!(map.get(&10), Some(&"ten"));
    assert_eq!(map.get(&40), None);

    if let Some(v) = map.get_mut(&10) {
        *v = "diez";
    }
    assert_eq!(map.get(&10), Some(&"diez"));

    let slice = map.as_slice();
    assert_eq!(slice, &[(10, "diez"), (20, "twenty-updated"), (30, "thirty")]);

    // 4. LiteMap removes entries by key, supports try_insert and try_append preserving sort invariants, and clears elements
    assert_eq!(map.try_insert(20, "duplicate"), Some((20, "duplicate")));
    assert_eq!(map.try_insert(25, "twenty-five"), None);
    assert_eq!(map.len(), 4);

    // try_append: only succeeds if strictly greater than last key
    assert_eq!(map.try_append(15, "fifteen"), Some((15, "fifteen")));
    assert_eq!(map.try_append(50, "fifty"), None);
    assert_eq!(map.len(), 5);

    let removed = map.remove(&25);
    assert_eq!(removed, Some("twenty-five"));
    assert_eq!(map.remove(&999), None);
    assert_eq!(map.len(), 4);

    let mut clearable: LiteMap<i32, &str> = LiteMap::new_vec();
    clearable.insert(1, "one");
    clearable.clear();
    assert!(clearable.is_empty());
    assert_eq!(clearable.len(), 0);

    // 5. LiteMap provides entry API for in-place vacant and occupied entry manipulation
    match map.entry(50) {
        Entry::Occupied(mut occ) => {
            assert_eq!(*occ.get(), "fifty");
            *occ.get_mut() = "fifty-modified";
        }
        Entry::Vacant(_) => panic!("expected occupied entry for 50"),
    }
    assert_eq!(map.get(&50), Some(&"fifty-modified"));

    match map.entry(100) {
        Entry::Vacant(vac) => {
            vac.insert("one-hundred");
        }
        Entry::Occupied(_) => panic!("expected vacant entry for 100"),
    }
    assert_eq!(map.get(&100), Some(&"one-hundred"));

    println!("All litemap contract assertions passed successfully.");
}

オリジンシーダー

匿名