This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//===--------------------~ Source ~--------------------===// | |
#include <stdint.h> | |
#ifndef offsetof | |
#define offsetof(type, member) ((uintptr_t)&((type*)0)->member) | |
#endif | |
#define CONTAINER_OF_CONST(member_ptr, container_ty, member_name) \ | |
((container_ty const*) ((uintptr_t) member_ptr - offsetof(container_ty, member_name))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::BTreeMap; | |
fn first_free_key<V>(map: &BTreeMap<usize, V>) -> usize { | |
map.keys() | |
.zip(map.keys().skip(1)) | |
.find(|(a, b)| (*b - *a) > 1) | |
.map(|(a, _)| *a + 1) | |
.unwrap_or_else(|| map.keys().last().map(|x| x + 1).unwrap_or(0)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn main() void { | |
const foo = Matrix(f32, 4, 4).identity(); | |
} | |
fn Matrix(comptime Scalar: type, comptime Width: usize, comptime Height: usize) type { | |
return struct { | |
const Self = @This(); | |
pub elems: [Width * Height]Scalar, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::cell::UnsafeCell; | |
use std::marker::PhantomData; | |
type EventReceiver<'a, A, R> = Box<dyn (FnMut(A) -> R + 'a)>; | |
struct Event<'a, A, R> { | |
receivers: Vec<UnsafeCell<EventReceiver<'a, A, R>>>, | |
_m: PhantomData<&'a ()>, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#include <cstddef> | |
#include <string> | |
#include <iostream> | |
struct TokIdentifier { | |
std::string name; | |
TokIdentifier() = delete; | |
TokIdentifier(TokIdentifier const &) = default; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const Controller = struct { | |
up: u1, | |
down: u1, | |
left: u1, | |
right: u1, | |
}; | |
pub fn main() void { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PAYLOAD_SIZE: usize = 128; | |
const TESTS: usize = 20; | |
fn main() { | |
let mut items: [Box<[u8; PAYLOAD_SIZE]>; TESTS] = unsafe { std::mem::uninitialized() }; | |
for item in items.iter_mut() { | |
unsafe { | |
std::ptr::write(item as *mut _, Box::new([0u8; PAYLOAD_SIZE])); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(generators, generator_trait)] | |
use std::ops::{Generator, GeneratorState}; | |
use std::thread; | |
use std::time::{Duration, Instant}; | |
struct CoStep; | |
impl CoGenerator for CoStep { | |
fn resume(&mut self) -> CoGenState { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::marker::PhantomData; | |
#[derive(Clone)] | |
struct App { | |
data: Vec<String>, | |
data2: Tester, | |
} | |
#[derive(Clone)] | |
struct Tester; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/id-Software/Quake-2/blob/372afde46e7defc9dd2d719a1732b8ace1fa096e/ref_soft/r_draw.c#L428 | |
void Draw_FadeScreen (void) | |
{ | |
int x,y; | |
byte *pbuf; | |
int t; | |
for (y=0 ; y<vid.height ; y++) | |
{ | |
pbuf = (byte *)(vid.buffer + vid.rowbytes*y); |
NewerOlder