Files
gists/archive/experimental/rust/uniq.rs
T
tobias 1cbf8afb4a chore: cleanup — untrack binaries, consolidate Go dirs, dedupe tools
- Untrack and delete compiled binaries (tarsum, gosoft.exe, rust uniq/uniq2);
  ignore build outputs (dist/, bin/, *.exe, *.test, .ruff_cache/)
- Merge tools/go/ and projects/go-tools/go/ into projects/go-tools/<name>/
- Fix goipgrep .gitignore: bare 'ipgrep' pattern was ignoring cmd/ipgrep/,
  so the main entrypoint was never tracked; now anchored to /ipgrep
- Archive duplicate implementations to archive/experimental/{rust,go}/
  (uniq, between, tarsum rewrites); canonical versions stay in tools/
- Update README tool catalog to match new layout

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 13:42:45 +02:00

42 lines
1.0 KiB
Rust

use std::env;
use std::fs::File;
use std::io::{self, BufRead, BufReader};
use std::collections::HashSet;
use std::hash::{Hash, Hasher};
use std::collections::hash_map::DefaultHasher;
fn main() -> io::Result<()> {
let args: Vec<String> = env::args().collect();
if args.len() > 1 {
for filename in &args[1..] {
let file = File::open(filename)?;
let reader = BufReader::new(file);
remove_duplicates(reader)?;
}
} else {
// No files provided, read from stdin
let stdin = io::stdin();
let reader = stdin.lock();
remove_duplicates(reader)?;
}
Ok(())
}
fn remove_duplicates<R: BufRead>(reader: R) -> io::Result<()> {
let mut seen_hashes = HashSet::new();
for line in reader.lines() {
let line = line?;
let mut hasher = DefaultHasher::new();
line.hash(&mut hasher);
let hash = hasher.finish();
if seen_hashes.insert(hash) {
println!("{}", line);
}
}
Ok(())
}