Skip to content

Instantly share code, notes, and snippets.

View greyblake's full-sized avatar
🇺🇦
#StandWithUkraine

Serhii Potapov greyblake

🇺🇦
#StandWithUkraine
View GitHub Profile
trait A {
fn a(&self);
}
trait B {
fn b(&self);
}
trait C {
fn c(&self);
use std::cell::Cell;
#[derive(Debug)]
struct Ab {
a: i32,
b: i32,
cache: Cell<Option<i32>>
}
impl Ab {
extern crate rand;
use rand::Rng;
const WIDTH : usize = 80;
const HEIGH : usize = 40;
const SIZE : usize = WIDTH * HEIGH;
type MatrixLine = [bool; WIDTH];
use std::ops::Mul;
#[derive(Debug)]
struct Vector {
x : f64,
y : f64
}
impl<'a> Mul<f64> for &'a Vector {
type Output = Vector;
#[derive(Debug)]
struct Point {
x : f64,
}
trait Math : {
fn sub(&self, &Self) -> Self;
fn add(&self, &Self) -> Self;
}
#[derive(Debug)]
struct Point {
x : f64,
}
trait Add {
fn add(&self, &Self) -> Self;
}
trait HasArea {
fn area(&self) -> f64;
}
struct Cyrcle {
radius : f64,
}
impl HasArea for Cyrcle {
fn main() {
let v1 = vec![4, 8, 12, 16];
let v2 = mult(&v1, 10);
pv("v1", &v1);
pv("v2", &v2);
println!("");
println!("{}", v1[2]);
fn main() {
let funcs = [
("+", sum as fn(f64, f64) -> f64),
("-", sub),
("*", mult),
("/", div),
("^", pow)
];
for &(name, func) in funcs.iter() {
# Benchmark of djb2, sdbm and lose lose hashing algorithms
# Algorithm descriptions: http://www.cse.yorku.ca/~oz/hash.html
# Output
#
# ===== djb2 =====
# Values: 5000000
# Collisions: 2988
# Time: 0.76589
#