1. Rob, How?
- Posted by No Solution <solutionnone at HOTMAIL.COM> Aug 18, 2000
- 506 views
Hello, Another question i have, for my own programming purposes, how did you implement the sequence idea in C/C++? i've attempted my own linked list class and a template class but none are stable enough to implement in a large program. Could you help me? Ian. ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
2. Re: Rob, How?
- Posted by Robert Craig <rds at ATTCANADA.NET> Aug 18, 2000
- 482 views
- Last edited Aug 19, 2000
Ian writes: > Another question i have, for my own programming purposes, > how did you implement the sequence idea in C/C++? > i've attempted my own linked list class and a template class > but none are stable enough to implement in a large program. If you look at the sieve C code that I released yesterday you'll get some idea. I originally (pre-1.0) implemented sequences as linked lists. The performance on random subscript operations was pretty poor, so I made them doubly-linked, and I kept a pointer in each sequence to the most recently referenced element. That helped a lot when you looped over a consecutive series of elements (as you often do). If you accessed x[25] followed by x[26], x[27], ... you could quickly locate the next element without starting at the beginning of the list and stepping through 25 elements. Eventually though I just implemented sequences as arrays. That made subscripting really fast, but things like append() became slower and had to be dealt with in a smarter way. More importantly, getting rid of all those links saved a ton of memory. Euphoria is implemented in plain C. I don't use any C++ features. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
3. Re: Rob, How?
- Posted by David Cuny <dcuny at LANSET.COM> Aug 18, 2000
- 478 views
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
4. Re: Rob, How?
- Posted by Mike The Spike <mikethespike2000 at HOTMAIL.COM> Aug 19, 2000
- 480 views
>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