Re: Rob, How?

new topic     » goto parent     » topic index » view thread      » older message » newer message

>No Solution wrote:
>
> > Another question i have, for my own programming
> > purposes, how did you implement the sequence idea
> > in C/C++?
>
>In the odd chance that Robert doesn't want to give away any trade secrets,
>you might want to take a look at Peuphoria, Pete's implementation of
>Euphoria. You can find it at:
>
>    http://www.harborside.com/~xseal/euphoria/
>
>-- David Cuny

Ah the hell.
Sequence are easy as crap to implement!
Sequences are just arrays!
If you're not so memory-hungry, but wanna have a fast implementation of
sequences (as fast or faster than Rob's) then do the following;

#define Slice 1
#define Integer 2
#define Double 3
#define Float 4

typedef struct
{
int * data;
char * mask;
} sequence;


// now to initialise a sequence, do this
sequence myseq;
myseq.data = (int*) malloc(sizeof(int)*10);
myseq.mask = (char*) malloc(10);

float f;
int i;
double d;

f = 50.1;
i = 70;
d = 500964.485;

myseq.data[1] = &f;
myseq.data[2] = &i;
myseq.data[3] = &d;
myseq.mask[1] = Float;
myseq.mask[2] = Integer;
myseq.mask[3] = Double.

// now you can extract the data in a sequence by getting the value
// at the integer address, and you can use the character mask to
// eventualy check the type of a given element. A Slice is just a
// pointer to another sequence, wich serves as a sub-sequence.


Above method sucks white ass sometimes. Allthough using realloc() you can
resize any part of the sequence pretty fast.
This method might not be that practical at times, but it's a hell of a lot
better than some of the ones I saw. It's fast, memory efficient, flexible,
and small.

The method I use is one simmiliar to the one above, except that I can
initialise whole sequences in one time without fetching the address of a
variable i'm puttin in there.


Sequences are no big secret, their a big joke for C programmers.
A C programmer can't use them in their code because they're not practical
for them, that's why you don't see C programs with sequences in them.

Atoms, though, are another story.
They *are* hard to implement because there is no way of doing fast math with
them. Everytime an Atom operation occurs the Atom must be checked to see if
it did not overflow. Atoms can be 4 or 8 bit integers or floats. And that's
what makes them a pain in the ass.


Mike The Spike
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu