Re: id field

David Calinski <[email protected]> Tue, 11 Nov 2003 13:04:58 +0100
Newsgroups gmane.comp.tools.memaid.devel
Message-ID <[email protected]>
On Tuesday 11 of November 2003 11:25, Fernando Antonio Mac Cracken Cezar 
wrote:
> On Tue, 2003-11-11 at 11:43, David Calinski wrote:
> > On Tuesday 11 of November 2003 10:33, Fernando Antonio Mac Cracken Cezar
> >
> > wrote:
> > > Talking the system time as id number may lead 2 or more
> > > cards to have the same id. If 2 cards are created in a given
> > > short period of time, the 2 successive system time calls may delivery
> > > the same value (this short period is SO dependent).
> >
> > Is anybody able to pass through 2 new items, and pick 2 grades for them,
> > in just 1 second?
>
> Yes. I do, better saying my software ;-) ... If I write for example a
> program to import a dictionary into my Memaid database, what actually I
> also want to write.

I's bad to write such thing to import items *directly* to MemAid database 
(elements.* file). But doing so you mess up with items - imported items will 
miss data from initial 'review', interval will be... ahem. Yuck!

(BTW: a script in contrib_1 package that imports data to MemAid format, is a 
pretty good example of a something one should never do, unless one imports 
data from another supermemo/memaid-like software, where items were *already* 
in a learning process.)

Instead, you should first import them to queue.txt, and they really will go to 
the learning process later, one-by-one, in more than one second space, unless 
you are so superman that you learn so quickly (more than 2 items in 1 
second) ... :)

> It isn't a nice approach to write a sleep
> statement before importing each new word, is it? ;-).

No, not nice. But after all, if anyone will have such a weird need to import 
items *directly* to MemAid database (which is generally very bad, as I said),
*then* one can came up with another solution for own needs (e.g. "take a 
random number and make a bit operation on top of the system time"), right?
For one time import you can solve it very simply: give your imported items 
numbers from 1 to... n, it won't conflict with other items until 2038 year.


> > > My suggestion is to take a random number and make a bit operation
> > > on top of the system time.
> >
> > That *can* result in a 2 same id, can't it?
>
> Yes, you're right. That was just a first suggestion, easy to implement
> and that would reduce the probability to have ID conflicts. But of
> course, better solutions are welcome .....

Sure they are very welcome.
So, anyone has a better solution than Unix time? :>


Note also, that if you will merge two databases, Unix time is your friend 
again:
bonus is that no two items will have the same ID (unless one is so superman, 
that one happened to learn *simultaneously* on two different databases, in 
the same second learn here and there.).
(Bonus is also that ID will show when an item has been introduced into 
learning process, which can be used in statistics - but it's not important 
here.)

Now, the only con I see is that one can really learn so quickly (and 
carelessly :-P), that can make two items in 1 second. O_o
But I highly doubt it's possible (have just done some test with a stop-watch   
- I can't achieve 2 items in 1 sec. even not looking at answer/questions.)

DC



-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/