first commit

This commit is contained in:
Ashborn 2025-12-16 22:10:06 +05:45
commit a66604eb6c
52 changed files with 790 additions and 0 deletions

7
collections/Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "collections"
version = "0.1.0"

6
collections/Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[package]
name = "collections"
version = "0.1.0"
edition = "2024"
[dependencies]

32
collections/src/main.rs Normal file
View file

@ -0,0 +1,32 @@
//collections are data structures provided by the standard library that store multiple values. They
//are more flexible than arrays and tuples, especially when the size or contents of the collectoin
//are not knows at compile tiem.
use std::collections::HashMap;
fn main() {
//vector
let mut numbers = vec![1,2,3];
numbers.pop();
println!("{:?}", numbers);
//hasmap
let mut scores = HashMap::new();
scores.insert("alice", 1);
if let Some(s) = scores.get("alice"){ //key is case sensitive
println!("{}", s);
}
for val in &numbers{
println!("{}", val);
}
}
//when to use what?
//random access by index = vector
//fast insertin and removal = vecDeque<T>
//need sorted keys = BTreeMap<k,v>
//set of unique items = hasset<t>
//prioirty queue = BinaryHeap<t>