|
honey the codewitch wrote: why write a database engine in c# Why not? It does the job
honey the codewitch wrote: In any case, you're being sweet. I won't hex you today. Probably because it's weekend and I don't have the energy to be mean
honey the codewitch wrote: my C# ISAM database code You still wrote it though.
|
|
|
|
|
Sander Rossel wrote: You still wrote it though.
Am writing it. Trying to do B+ trees. And once i get them working for in-memory i have to make them diskable, and you can't just use serialization. You have to keep an open file pointer and seek periodically and read/write the blocks you need. It's that kind of file I/O, so i'm still a ways off. I hope to have the B+ tree at least solidly in progress by tonight but we'll see.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
here's the main render loop for Prang Replay, my midi looper for FL Studio
void _stdcall Replay::Gen_Render(PWAV32FS DestBuffer, int &Length) {
unsigned long long p = looper.pos;
int bts = looper.beats;
float bps = looper.tempo / 60;
float spb = looper.sampleRate / bps;
unsigned long long i = 0;
midi_message midi;
vector<Loop>& loops = looper.loops;
if (1 < loops.size() && looper.rol != looper.ror) {
if(looper.rol) {
loops.push_back(*loops.begin());
loops.erase(loops.begin());
if (-1 < looper.lastPushIndex) {
--looper.lastPushIndex;
if (0 > looper.lastPushIndex)
looper.lastPushIndex += looper.loops.size();
}
looper.rol = false;
}
if(looper.ror) {
loops.insert(loops.begin(), (*(loops.end() - 1)));
loops.pop_back();
if (-1 < looper.lastPushIndex) {
++looper.lastPushIndex;
if ((int)looper.loops.size() <= looper.lastPushIndex)
looper.lastPushIndex -= looper.loops.size();
}
looper.ror = false;
}
}
else
looper.rol = looper.ror = false;
if(looper.push) {
if (0xFFFFFFFFFFFFFFFF!=looper.tapPos) { unsigned long long len = p - looper.tapPos;
i = (unsigned long long)ceil(len / spb);
i = ((unsigned long long)ceil(i / bts))*bts; bts = (int)i;
if (0 == bts)
bts = looper.beats;
}
if (bts)
{
unsigned long long bp = p;
vector<midi_event>::iterator it = looper.events.end() - 1;
vector<midi_event>::iterator cur = it;
unsigned long long bl = (unsigned long long)(spb*bts);
unsigned long long bs = bp - bl;
if (looper.events.size()) {
while ((*it).pos > bs) {
--it;
if (looper.events.begin() == it)
break;
}
while (looper.events.end() != it && it->pos < bs)
++it;
}
Loop loop;
loop.eventIndex = 0;
loop.length = bl;
loop.pos = 0;
if (looper.events.size()) {
while (it <= cur) {
midi_event ev(*it);
ev.pos -= bs;
loop.events.push_back(ev);
++it;
}
}
loops.push_back(loop);
looper.hanging = looper.keyContext; looper.lastPushIndex = loops.size() - 1;
}
looper.push = 0;
looper.tapPos = 0xFFFFFFFFFFFFFFFF;
pEditor->ParamsToControls();
}
vector<Loop>::iterator it = loops.begin();
while (it != loops.end()) {
Loop& loop = (*it);
int lec = loop.events.size();
if (lec) {
while (loop.eventIndex >= lec)
loop.eventIndex -= lec;
unsigned long long n = Length + loop.pos;
int nc = 0;
while (true) {
unsigned long long lp = loop.events[loop.eventIndex].pos;
if (lp < loop.pos)
lp += loop.pos;
if(lp<n) {
midi = loop.events[loop.eventIndex].midi;
loop.noteCounter.process_message(midi);
looper.noteCounter.process_message(midi);
midi = looper.noteCounter.filter_message(midi);
if (looper.enabled && midi.status)
PlugHost->MIDIOut_Delayed(HostTag, (int)midi);
}
else break;
++loop.eventIndex;
if (loop.eventIndex >= lec)
loop.eventIndex -= lec;
++nc; if (nc == lec) break;
}
loop.pos += Length;
if (loop.pos > loop.length)
loop.pos -= loop.length;
} else
it->pos+=Length;
while (it->pos >= it->length)
it->pos -= it->length;
++it;
}
while ((size_t)looper.eventIndex < looper.events.size()) {
midi_event e(looper.events[looper.eventIndex]);
if (Length <= e.pos - p)
break;
looper.noteCounter.process_message(e.midi);
looper.incomingNoteCounter.process_message(e.midi);
midi_message m = looper.noteCounter.filter_message(e.midi);
if(looper.enabled && 0!=m.status)
PlugHost->MIDIOut_Delayed(HostTag, (int)m);
++looper.eventIndex;
}
if(looper.pop) {
if (loops.size()) {
Loop* ploop = &(*loops.rbegin());
for (int i = 0; i < 16; ++i) { for (int j = 0; j < 128; ++j) { looper.noteCounter.note[i][j]-=ploop->noteCounter.note[i][j];
if (looper.noteCounter.note[i][j] <= 0 && ploop->noteCounter.note[i][j] > 0) {
looper.noteCounter.note[i][j] = 0;
midi_message m;
m.extra = midiOut;
m.status = 0x80 | i;
m.data1 = j;
m.data2 = 0;
PlugHost->MIDIOut_Delayed(HostTag, (int)m); }
}
}
loops.pop_back();
}
if (looper.loops.size() == looper.lastPushIndex)
--looper.lastPushIndex;
looper.pop = 0;
}
looper.pos += Length;
Length = 0;
}
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
No - it's long gone.
Is it OK if I use one of yours, instead?
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
use the above. It frightens animals and small children.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
No, but I remember what it was.
Duff's device laid on top of an if-else.
|
|
|
|
|
+1 I had to look up Duff's device. I've done it before, but i never knew it had a name.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I believe this was the function that made me completely reevaluate my approach to parsing. Ultimately, I came up with something FAR simpler, that wasn't going to be a nightmare to change when adding another condition to the code.
bool parser::parseExecute()
{
tokStruct_ *workTokStack;
precedence_ *workPrecStack;
int numTok=0, numPrec=0;
tokStackPos = -1;
if (!setupTokStackMem(&workTokStack, ansStackAlloc) ||
!setupPrecStackMem(&workPrecStack, ansStackAlloc)) {
MsgBox("Unable to allocate memory in ExecuteToken");
return false;
}
workPrecStack[0] = PrecGet;
workTokStack[0].token = TokGet;
do {
++tokStackPos;
if (tokStack[tokStackPos].token == TokValue) {
ansStack[++ansStackPos] = valStack[tokStack[tokStackPos].varListPos];
continue;
}
if (tokStack[tokStackPos].token == Tok0DimVar) {
ansStack[++ansStackPos] = getValFromVarList();
continue;
}
if (tokStack[tokStackPos].token == TokMDimVarEnd) {
if (workTokStack[tokStackPos-1].token == TokMDimVarAssign) break;
if (workTokStack[tokStackPos-1].token != TokMDimVar) {
MsgBox("']' encountered without arrayed variable");
return moveCursorToError(origStr);
}
int Y, Z, pos, dim;
Y = varList[workTokStack[numTok-1].varListPos].Y;
Z = varList[workTokStack[numTok-1].varListPos].Z;
dim = varList[workTokStack[numTok-1].varListPos].varDim;
if (dim == 1) pos = ansStack[ansStackPos];
else if (dim == 2) pos = ansStack[ansStackPos-1] +
ansStack[ansStackPos]*Y;
else if (dim == 3) pos = ansStack[ansStackPos-2] +
ansStack[ansStackPos-1]*Y + ansStack[ansStackPos]*Y*Z;
ansStackPos = ansStackPos-dim+1;
if (varList[workTokStack[numTok-1].varListPos].varType == Int) {
ansStack[ansStackPos] =
*((int*)(varList[workTokStack[numTok-1].varListPos].varAddress)+pos);
}
else if (varList[workTokStack[numTok-1].varListPos].varType == Double) {
ansStack[ansStackPos] =
*((double*)(varList[workTokStack[numTok-1].varListPos].varAddress)+pos);
}
else {
MsgBox("Bad varType placed on ansStack");
return moveCursorToError(origStr);
}
ansStackPos++;
numTok--; continue;
}
++numTok; ++numPrec;
workTokStack[numTok] = tokStack[tokStackPos];
workPrecStack[numPrec] = precStack[tokStackPos];
if (workTokStack[numTok].token == TokLParen) continue;
while (workPrecStack[numPrec-1] >= workPrecStack[numPrec]) {
workPrecStack[numPrec-1] = workPrecStack[numPrec];
numPrec--;
switch (workTokStack[numTok-1].token) {
case TokValue: ansStack[++ansStackPos] =
*(double*)varList[workTokStack[numTok-1].varListPos].varAddress;
numTok++;
numPrec++;
tokStackPos++;
break;
case TokVarAssign: if (ansStackPos != 0) {
MsgBox("Malformed statement");
delete workTokStack;
delete workPrecStack;
return false;
}
*(double*)varList[workTokStack[numTok-1].varListPos].varAddress = ansStack[0];
numTok=numTok-2;
numPrec--;
ansStackPos--;
goto pETBreakout;
case TokAdd: ansStack[ansStackPos-1] = ansStack[ansStackPos-1] + ansStack[ansStackPos];
ansStackPos--;
numTok--;
break;
case TokSubtract:
ansStack[ansStackPos-1] = ansStack[ansStackPos-1] - ansStack[ansStackPos];
ansStackPos--;
numTok--;
break;
case TokMultiply:
ansStack[ansStackPos-1] = ansStack[ansStackPos-1] * ansStack[ansStackPos];
ansStackPos--;
numTok--;
break;
case TokDivide:
ansStack[ansStackPos-1] = ansStack[ansStackPos-1] / ansStack[ansStackPos];
ansStackPos--;
numTok--;
break;
case TokPower:
ansStack[ansStackPos-1] = pow(ansStack[ansStackPos-1], ansStack[ansStackPos]);
ansStackPos--;
numTok--;
break;
case TokSemiCol: if (ansStackPos != 0) {
MsgBox("Misformed Statement");
delete workTokStack;
delete workPrecStack;
return false;
}
ansStackPos--;
break;
case TokComma:
numTok--;
break;
case TokLParen:
if (tokStack[tokStackPos].token == TokLParen &&
tokStack[tokStackPos-1].token == TokLParen) {
numPrec++;
goto pETBreakout;
}
numTok=numTok-2;
numPrec--;
goto pETBreakout;
case TokRParen:
break;
case TokMDimVar:
int Y, Z, pos, dim;
Y = varList[workTokStack[numTok-1].varListPos].Y;
Z = varList[workTokStack[numTok-1].varListPos].Z;
dim = varList[workTokStack[numTok-1].varListPos].varDim;
if (dim == 1) pos = ansStack[ansStackPos-1];
else if (dim == 2) pos = ansStack[ansStackPos-2] +
ansStack[ansStackPos-1]*Y;
else if (dim == 3) pos = ansStack[ansStackPos-3] +
ansStack[ansStackPos-2]*Y + ansStack[ansStackPos-1]*Y*Z;
if (varList[workTokStack[numTok-1].varListPos].varType == Int) {
*((int*)(varList[workTokStack[numTok-1].varListPos].varAddress)+pos) =
ansStack[ansStackPos];
}
else if (varList[workTokStack[numTok-1].varListPos].varType == Double) {
*((double*)(varList[workTokStack[numTok-1].varListPos].varAddress)+pos) =
ansStack[ansStackPos];
}
else {
MsgBox("Bad varType placed on ansStack");
return moveCursorToError(origStr);
}
ansStackPos = ansStackPos-dim;
numTok--; continue;
default:
MsgBox("Still Programming!");
delete workTokStack;
delete workPrecStack;
return false;
}
workTokStack[numTok] = workTokStack[numTok+1];
} pETBreakout:
} while (workPrecStack[numPrec] != PrecEnd);
delete workPrecStack; workPrecStack = NULL;
delete workTokStack; workTokStack = NULL;
return true;
}
|
|
|
|
|
yeah, two stacks is complicated.
you should just need the one at most (not even that if you're borrowing *the* stack (call stack) using recursive descent.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Pfft. That's art to the stuff I've written. My stuff is so bad if I posted it here your computer would keel over in fright and refuse to reboot.
cheers
Chris Maunder
|
|
|
|
|
I'm glad i'm not the only target of Sander and his pitchfork.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Yes you are.
Speaking of which...
|
|
|
|
|
i'll turn you into a VB6 developer
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Been there done that
|
|
|
|
|
In that case I'll hex your boss so you get stuck on front end work.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I'm my own boss
|
|
|
|
|
Even better.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Is it part of the code behind CP...?
|
|
|
|
|
dandy72 wrote: the code behind CP
No.
That code's even worse
cheers
Chris Maunder
|
|
|
|
|
Yes, and it's a work of art. Picasso is also art mind you.
I spent two weeks on it and it solved quite a few problems in one go.
<edit>Two different ways to parse a tree and a statemachine for the nodes.</edit>
I was very proud of it at the moment.
Today I look at it and think WTF!
modified 13-Sep-19 18:37pm.
|
|
|
|
|
And I thought ugly functions are only written in ... VB.
|
|
|
|
|
I started writing one about a month ago, and I'm still not finished.
|
|
|
|
|
sounds familiar. the one in the OP took two weeks to get to that.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
PITCHFORK TIME!
I can't remember the ugliest I've ever written, but a recent one was something like this (I can't post the actual code):
if (...)
{
if (...)
{
}
if (...)
{
}
foreach (...)
{
}
}
else
{
if (...)
{
foreach (...)
{
if (...)
{
}
foreach (...)
{
}
}
}
else
{
if (...)
{
foreach (...)
{
}
}
}
} Total of 64 lines long
And that's already the refactored function.
That entire class is a bit of a mess.
I have to convert a flat CSV file to some multi-layered standard with mandatory fields (that aren't necessary in the CSV), default values, some interpreted values, etc.
The class has 37 if's in total.
That's about as much as I usually have in an entire project
Compared to your multi layered mess of single line if statements it's still a work of beauty though
|
|
|
|
|
but can it parse html?
can it index a million rows of data?
*raises eyebrow*
when you do witchy things, your code will finally look witchy as a result.
just like when you're writing your code that deals with a mess of input your code looks like a mess.
we are a product of our environment, and so is our code.
my code comes from a crazy person. it shall reflect that.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|