Skip to content

Instantly share code, notes, and snippets.

@lkuper
Created June 6, 2012 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lkuper/2885573 to your computer and use it in GitHub Desktop.
Save lkuper/2885573 to your computer and use it in GitHub Desktop.
fn main() {
// Bitvector to represent sets of integral types
type int_ty_set = uint;
impl methods for int_ty_set {
fn union(s: int_ty_set) -> int_ty_set { self | s }
fn intersection(s: int_ty_set) -> int_ty_set { self & s }
// Returns true if singleton_set's member is a member of self,
// and false otherwise.
fn contains(singleton_set: int_ty_set) -> bool {
(self & singleton_set) == 0u
}
}
fn mk() -> int_ty_set { 0b00000000000u }
// Methods returning constants, representing singleton sets
// containing each of the integral types
fn only_ty_i() -> int_ty_set { 0b00000000001u }
// todo: need this one?
fn only_ty_char() -> int_ty_set { 0b00000000010u }
fn only_ty_i8() -> int_ty_set { 0b00000000100u }
fn only_ty_i16() -> int_ty_set { 0b00000001000u }
fn only_ty_i32() -> int_ty_set { 0b00000010000u }
fn only_ty_i64() -> int_ty_set { 0b00000100000u }
fn only_ty_u() -> int_ty_set { 0b00001000000u }
fn only_ty_u8() -> int_ty_set { 0b00010000000u }
fn only_ty_u16() -> int_ty_set { 0b00100000000u }
fn only_ty_u32() -> int_ty_set { 0b01000000000u }
fn only_ty_u64() -> int_ty_set { 0b10000000000u }
let mut x: int_ty_set = only_ty_i();
x = x.union(only_ty_char());
log(error, x.contains(only_ty_i()));
log(error, x.contains(only_ty_char()));
log(error, x.contains(only_ty_i8()));
log(error, x.contains(only_ty_u64()));
x = x.union(only_ty_u64());
log(error, x.contains(only_ty_i()));
log(error, x.contains(only_ty_char()));
log(error, x.contains(only_ty_i8()));
log(error, x.contains(only_ty_u64()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment