Last active
January 12, 2016 11:51
-
-
Save mientjan/e5a8006f1c5e5a98edcc to your computer and use it in GitHub Desktop.
This file contains 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
// A bitwise FlagMachine | |
// create a enum | |
enum PizzaIngredients { | |
BREAD = 1 << 0, | |
CHEESE = 1 << 1, | |
TOMATO = 1 << 2, | |
UNIONS = 1 << 3, | |
GARLIC = 1 << 4, | |
} | |
var pizzaMozzarella = new Flag<PizzaIngredients>(PizzaIngredients.BREAD | PizzaIngredients.TOMATO | PizzaIngredients.CHEESE); | |
var garlicBread = new Flag<PizzaIngredients>(PizzaIngredients.BREAD | PizzaIngredients.GARLIC); | |
var pizza = new Flag<PizzaIngredients>(); | |
pizza.add( PizzaIngredients.BREAD | PizzaIngredients.TOMATO | PizzaIngredients.CHEESE ); | |
pizza.equals(pizzaMozzarella); // true | |
pizza.add(garlicBread); // true | |
pizza.contains(garlicBread); // true | |
pizza.equals(pizzaMozzarella); // false because PizzaMozzarella contains no garlic | |
pizza.equals(pizzaMozzarella | PizzaIngredients.GARLIC); // true now it does |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment