Menu
Home
Create new Paste
Log in
BigOh neato
Code
Theme: cobalt
Theme: eclipse
Theme: elegant
Theme: monokai
Theme: neat
Theme: night
Theme: rubyblue
struct BigO { double exp = 0, logExp = 0; bool opEqual(BigO rhs) const { return exp == rhs.exp && logExp == rhs.logExp; } int opCmp(BigO rhs) const { if (exp == rhs.exp) return logExp < rhs.logExp ? -1 : (logExp > rhs.logExp); return exp > rhs.exp ? 1 : -1; } BigO opMul(BigO rhs) const { return BigO(exp + rhs.exp, logExp + rhs.logExp); } static immutable constant = BigO(), logarithmic = BigO(0, 1), sqrt = BigO(0.5), linear = BigO(1), linearithmic = BigO(1, 1), quadratic = BigO(2), cubic = BigO(3), fastGrowing = BigO(double.infinity); } BigO complexity(alias fun)() { enum traits = __traits(getAttributes, fun); foreach (i, trait; traits) { static if (is(typeof(trait) : const BigO)) return trait; } return BigO(); } struct List(T) { void insertFront(T x) @(BigO.constant); } void main() { List!int lst; static assert(complexity!(List!int.insertFront) == BigO.constant); static assert(complexity!(List!int.insertFront) < BigO.quadratic); assert(BigO.constant * BigO.linear == BigO.linear); }
Result:
Success
/
Return code: 0
Paste info
Author:
Guest
Views:
492
Private:
no
Expires:
Never
Uploaded:
05.12.15 19:58
Votes
:
0
Tweet
Compilation
Compiler:
DMD 2.079.1 ( 2.079.1 )
Pointer size:
m64
Actions
Download
Raw
×
Confirm
Are you sure you want to delete this paste?
There's no way back!
×
Confirm
Reason