unique id generation

From: Tomas Frydrych (tomas@frydrych.uklinux.net)
Date: Sat May 17 2003 - 16:02:53 EDT

  • Next message: Tomas Frydrych: "commit (HEAD)"

    The way we generate id's for various things in the document, such as
    headers, footnotes and lists is a real mess; in our code there are
    three different methods used to create what are are supposed to be
    unique id's:

    1. using UT_rand: randomness does not guarantee uniqueness, as the
    generator can produce duplicate numbers before exhausting all
    possibilities. It creates the impression of uniqueness, which will
    sooner or later come to haunt us.

    2. Using sequential generation: this is used in bits and pieces of
    our importer code; it guarantees uniquness while importing, but once
    we enter editing mode, we have lost control. Further more, as there
    is no relationship between the state of the rand generator used in
    the editing mode and the id's sequentially generated on import, our
    chances of non-uniquness are incereased.

    3. reusing id's stored in the imported document; same problem as (2).

    Neither of the three methods above is good enough, and the present
    state of things has to change before the 2.0 release. The bottom
    line: unique id's need to be generated on document level and have to
    be unique.

    So I have implemented UT_UniqueId class (ut_misc.h/cpp) and
    PD_Document methods getUID(type) and setMinUID(type, min), which I
    will commit as soon as I can get into the CVS, and I am going to
    start working on moving all our code to using these.

    For the mainteners of importers, this is how it will work: (1) when a

    unique id is to be generated it will be generated using the
    PD_Document::getUID() method. (2) if a unique numerical id stored in
    the document is being reused, the importer needs to call
    PD_Document::setMinUID() to ensure that any future generated id's
    will be greater than this. (3) if a unique alphanumerical id stored
    in the document is being reused, the importer needs to take similar
    steps to ensure that this id cannot be reduplicated in the editing
    mode.

    Exporters: stick to numerical id's as much as possible, it will make
    our life much simpler.

    Tomas

    Tomas



    This archive was generated by hypermail 2.1.4 : Tue May 20 2003 - 10:09:09 EDT