Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Hey /prog/

Name: Anonymous 2012-03-07 3:41

improve my virtual machine

git clone https://code.google.com/p/gpvm/

Forgive my lack of documentation. This will be remidied shortly. Also, some instructions remain unimplemented, as I haven't found a use for them yet.

Also, note the absolute lack of references (int &a = b). Haskell has created the idea in my head they are not needed, but I can see them being useful and I will almost undoubtedly implement them at some point.

I look forward to sorting through your abuse to see if anyone says anything constructive.

Name: Anonymous 2012-03-10 3:05

>>50
And another way is to create a balanced binary tree and then inline it as a series of if else statements:


switch(n) {
  case 1: a();
  case 10: b();
  case 100: c();
  case 1000: d();
  case 10000: e();
  case 100000: f();
  case 1000000: g();
  default: h();
}


=> binary tree:


     _____1000_____
    /              \
   10             100000
  /  \           /      \
 1   100     10000       1000000


--> balanced if else chain:


if(n == 1000) {
  d();
} else if(n > 1000) {
  if(n == 100000) {
    f();
  } else if(n > 100000) {
    if(n == 1000000) {
      g();
    } else {
      h();
    }
  } else {  // 1000 < n < 100000
    if(n == 10000) {
      e();
    } else {
      h();
    }
  }
} else { // n < 1000
  if(n == 10) {
    b();
  } else if(n > 10) { // 10 < n < 1000
    if(n == 100) {
      c();
    } else {
      h();
    }
  } else { // n < 10
    if(n == 1) {
      a();
    } else {
      h();
    }
  }
}


In the worst case, there will be log(n) comparisons performed.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List