commit: abi: "hash maps", or "in search of greener code"

From: F J Franklin (F.J.Franklin@sheffield.ac.uk)
Date: Mon May 12 2003 - 16:36:03 EDT

  • Next message: Hubert Figuiere: "dropping BeOS port"

    Well, I've been playing with hash maps during the past few days and I'm
    feeling sufficient confident now to put them to use. I haven't touched
    UT_StringPtrMap or even subclassed it. It has always seemed unnecessarily
    complicated to me, and I hate having to explicitly UT_ENEMA() it.

    Not saying UT_StringPtrMap is bad, I'm sure all those magic numbers make
    it a wizard class, but I get a headache everytime I try to use it.

    Anyway.

    Four hash maps are defined in ut_IntStrMap.[h|cpp]:

    1. UT_IntStrMap

       Maps integers to UTF-8 strings, e.g. map[1] == "one"

    2. UT_NumberMap

       Maps UTF-8 strings to integers, e.g. map["one"] == 1

    3. UT_GenericUTF8Hash

       An alternative to UT_StringPtrMap (defined in ut_hash.h) but
       restricted to UTF-8 string keys; one important difference is that
       UT_GenericUTF8Hash automatically free()s/deletes its contents.
       Can't be instantiated, but isn't abstract. Designed for easy
       subclassing.

       This hash stores values which are subclasses of a purely abstract
       base class UT_GenericBase which is declared in ut_string_class.h,
       which allows them to be deleted by the hash and this makes book-keeping
       a little easier.

    4. UT_UTF8Hash

       Useful subclass of UT_GenericUTF8Hash which maps UTF-8 strings to
       UTF-8 strings, e.g. map["one"] == "1"

    With some trepidation I've put UT_NumberMap to work in IE_Imp_XML, mapping
    element names to token integer IDs (Bug 3605, reopened by me).

    I've also re-written ap_Dialog_Paragraph a little to work around the whole
    integers-stored-as-pointers mess (Bug 3614).

    o ut_string_class:
    - declare new purely abstract UT_GenericBase class
    - make UT_UTF8String a subclass of UT_GenericBase
    o ut_IntStrMap:
    - fix bug in UT_IntStrMap (UT_sint32 -> UT_UTF8String )
    - add UT_NumberMap (UT_UTF8String -> UT_sint32 )
    - add UT_GenericUTF8Hash (UT_UTF8String -> UT_GenericBase)
    - add UT_UTF8Hash (UT_UTF8String -> UT_UTF8String )
    o use UT_NumberMap in ie_imp_XML (Bug 3605, reopened by me)
    o rewrite ap_Dialog_Paragraph to work around int/pointer issues (Bug 3614)

    CVS:----------------------------------------------------------------------
    CVS: Enter Log. Lines beginning with `CVS:' are removed automatically
    CVS:
    CVS: Committing in .
    CVS:
    CVS: Modified Files:
    CVS: src/af/util/xp/ut_IntStrMap.cpp src/af/util/xp/ut_IntStrMap.h
    CVS: src/af/util/xp/ut_string_class.cpp
    CVS: src/af/util/xp/ut_string_class.h
    CVS: src/wp/ap/xp/ap_Dialog_Paragraph.cpp
    CVS: src/wp/ap/xp/ap_Dialog_Paragraph.h
    CVS: src/wp/impexp/xp/ie_imp_XML.cpp src/wp/impexp/xp/ie_imp_XML.h
    CVS:----------------------------------------------------------------------

    Regards, Frank

    Francis James Franklin
    F.J.Franklin@shef.ac.uk

    After we were introduced I noticed that both of them were carrying
    three-foot-long machetes. I hate hiking with convicts carrying machetes.

                                            - Susan Orlean, The Orchid Thief



    This archive was generated by hypermail 2.1.4 : Mon May 12 2003 - 16:49:17 EDT