Changeset 56

Show
Ignore:
Timestamp:
04/03/08 06:48:19 (4 years ago)
Author:
maxter
Message:

Removed the time-based generator, sys and ipc packages. Added more API documentation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/scrapple/util/uuid/NameUuidGen.d

    r50 r56  
    99        With the functions in this module, UUIDs can be created from names 
    1010        that are unique within a name space. 
    11          
     11 
    1212        MD-5 or SHA-1 hashing algorithms can be used to generate a name-based UUID. 
    1313        If backward compatibility is not an issue, SHA-1 should be preferred. 
    14          
     14 
    1515        The functions are thread-safe. 
    1616 
     
    3939 
    4040    Uuid uuid = digest.binaryDigest; 
    41     uuid.ver = ver
    42     uuid.variant = UuidVariant.Standard
     41    uuid.versionTimeHigh = (uuid.versionTimeHigh & 0x0FFF) | (ver << 12)
     42    uuid.variantClockSeqHigh = (uuid.variantClockSeqHigh & 0x3F) | 0x80
    4343 
    4444    return uuid; 
     
    9696} 
    9797 
    98 version (UuidUnitTest) 
     98debug (UuidUnitTest) 
    9999{ 
    100100    import tango.io.Stdout; 
     
    125125 
    126126        // Namespace uuids 
    127         assert (NameSpaceUuids.dns  == cast(Uuid)"6ba7b810-9dad-11d1-80b4-00c04fd430c8"); 
    128         assert (NameSpaceUuids.url  == cast(Uuid)"6ba7b811-9dad-11d1-80b4-00c04fd430c8"); 
    129         assert (NameSpaceUuids.oid  == cast(Uuid)"6ba7b812-9dad-11d1-80b4-00c04fd430c8"); 
    130         assert (NameSpaceUuids.x500 == cast(Uuid)"6ba7b814-9dad-11d1-80b4-00c04fd430c8"); 
     127        assert (NameSpaceUuids.dns  == Uuid("6ba7b810-9dad-11d1-80b4-00c04fd430c8")); 
     128        assert (NameSpaceUuids.url  == Uuid("6ba7b811-9dad-11d1-80b4-00c04fd430c8")); 
     129        assert (NameSpaceUuids.oid  == Uuid("6ba7b812-9dad-11d1-80b4-00c04fd430c8")); 
     130        assert (NameSpaceUuids.x500 == Uuid("6ba7b814-9dad-11d1-80b4-00c04fd430c8")); 
    131131 
    132132    } 
  • trunk/tango/scrapple/util/uuid/NativeUuidGen.d

    r50 r56  
    106106    return uuid; 
    107107} 
     108 
     109debug (UuidUnitTest) 
     110{ 
     111    import tango.io.Stdout; 
     112    unittest 
     113    { 
     114        assert (newUuid != newUuid); 
     115        assert (newTimeUuid != newTimeUuid); 
     116    } 
     117} 
  • trunk/tango/scrapple/util/uuid/RandomUuidGen.d

    r50 r56  
    9494const RandomUuidGen!(typeof(&crand)) newUuid = { &crand }; 
    9595 
    96 version (UuidUnitTest) 
     96debug (UuidUnitTest) 
    9797{ 
    9898    import tango.math.Random; 
  • trunk/tango/scrapple/util/uuid/Uuid.d

    r50 r56  
    77        authorS:        Max Samukha 
    88 
    9         This module defines the 128-bit Universally Unique Identifier structure 
     9        This module defines a 128-bit Universally Unique Identifier structure 
    1010        conforming to Proposed Stardard RFC-4122. 
    1111 
     
    3333import tango.core.Exception; 
    3434 
    35 debug 
    36 { 
    37     import 
    38         tango.io.Stdout, 
    39         tango.io.Console, 
    40         tango.io.FileConduit; 
    41 } 
    42  
    4335private 
    4436{ 
    45     const char[] INVALID_UUID_STR_MSG = "Invalid UUID string format"; 
    46     const char[] DIGITS = "0123456789abcdef"; 
     37    const char[] InvalidUuidMsg = "Invalid UUID string format"; 
     38    const char[] Digits = "0123456789abcdef"; 
    4739} 
    4840 
     
    6254    int cCount; 
    6355 
    64     foreach (i, d; DIGITS
     56    foreach (i, d; Digits
    6557    { 
    6658        if (d == c1) 
     
    8779    assert (hex.length == 2); 
    8880 
    89     hex[0] = DIGITS[ub >> 4]; 
    90     hex[1] = DIGITS[ub & 0x0F]; 
     81    hex[0] = Digits[ub >> 4]; 
     82    hex[1] = Digits[ub & 0x0F]; 
    9183} 
    9284 
    9385/***************************************************************************************** 
    94    Uuid variants
     86   The UUID variants. The UUID variant determines the layout of the UUID
    9587*****************************************************************************************/ 
    9688enum UuidVariant : ubyte 
    9789{ 
    98     /// 
     90    /// Reserved, NCS backward compatibility. 
    9991    Ncs, 
    100     /// 
     92    /// The UUID is compatible with RFC-4122. 
    10193    Standard, 
    102     /// 
     94    /// Reserved, _Microsoft backward compatibility. 
    10395    Microsoft, 
    104     /// 
     96    /// Reserved for future definition. 
    10597    Future 
    10698} 
    10799 
    108100/***************************************************************************************** 
    109    Uuid versions
     101    Versions of a standard UUID
    110102*****************************************************************************************/ 
    111103enum UuidVersion : ubyte 
    112104{ 
    113     /// 
     105    /// The time-based version. 
    114106    TimeBased = 1, 
    115     /// 
     107    /// The DCE security version, with embedded POSIX UIDs. 
    116108    Dce = 2, 
    117     /// 
     109    /// The name-based version that uses MD5 hashing. 
    118110    NameBasedMd5 = 3, 
    119     /// 
     111    /// The randomly or pseudo-randomly generated version. 
    120112    Random = 4, 
    121     /// 
     113    /// The name-based version specified that uses SHA1 hashing. 
    122114    NameBasedSha1 = 5 
    123115} 
     
    130122    align(1): 
    131123 
    132     /// 
     124    /// The low field of the timestamp. 
    133125    uint timeLow; 
    134     /// 
     126    /// The middle field of the timestamp. 
    135127    ushort timeMid; 
    136     /// 
     128    /// The high field of the timestamp multiplexed with the version number. 
    137129    ushort versionTimeHigh; 
    138     /// 
     130    /// The high field of the clock sequence multiplexed with the variant. 
    139131    ubyte variantClockSeqHigh; 
    140     /// 
     132    /// The low field of the clock sequence. 
    141133    ubyte clockSeqLow; 
    142     /// 
     134    /// The spatially unique node identifier. 
    143135    ubyte[6] node; 
    144136 
     
    146138    { 
    147139        /***************************************************************************************** 
    148             Length of the string representation of a UUID, in UTF-8 characters (36). 
     140            The length of the string representation of a UUID (36 characters). 
    149141        *****************************************************************************************/ 
    150142        StringLength = 36 
     
    227219 
    228220        Params: 
    229             ver  = UUID version. 
    230     *****************************************************************************************/ 
    231     UuidVersion ver(UuidVersion ver
     221            v  = UUID version. 
     222    *****************************************************************************************/ 
     223    UuidVersion ver(UuidVersion v
    232224    { 
    233225        versionTimeHigh = (versionTimeHigh & 0x0FFF) | (ver << 12); 
     
    406398                str[18] != '-' || str[23] != '-') 
    407399        { 
    408             throw new IllegalArgumentException(INVALID_UUID_STR_MSG); 
     400            throw new IllegalArgumentException(InvalidUuidMsg); 
    409401        } 
    410402 
     
    422414 
    423415            if (!hexToUbyte(str[cIdx..cIdx + 2], ub)) 
    424                 throw new IllegalArgumentException(INVALID_UUID_STR_MSG); 
     416                throw new IllegalArgumentException(InvalidUuidMsg); 
    425417 
    426418            octets[octIdx] = ub; 
     
    434426 
    435427        return result; 
    436     } 
    437  
    438     /***************************************************************************************** 
    439         Casts the UUID to its string representation. 
    440     *****************************************************************************************/ 
    441     char[] opCast() 
    442     { 
    443         return toString; 
    444428    } 
    445429 
     
    526510} 
    527511 
    528 version (UuidUnitTest) 
     512debug (UuidUnitTest) 
    529513{ 
    530514    unittest 
     
    561545        uuid = testUuidStr; 
    562546        assert(uuid.toString == testUuidStr); 
    563         assert(testUuidStr == cast(char[])uuid); 
    564547 
    565548        ubyte[] octets = uuid.toOctets; 
     
    608591} 
    609592 
    610 // TODO: add sane unittests and remove this 
    611 version (UuidStandalone) 
    612 
    613     //import tango.scrapple.util.uuid.TimeBased; 
    614     //import tango.scrapple.util.uuid.Random; 
    615     import tango.scrapple.util.uuid.ipc.SharedMemoryObject; 
    616     import tango.scrapple.util.uuid.ipc.MappableFile; 
    617     import tango.scrapple.util.uuid.ipc.AutoSemaphore; 
    618     import tango.scrapple.util.uuid.ipc.NamedSemaphore; 
    619     import tango.scrapple.util.uuid.TimeUuidGen; 
    620     import tango.scrapple.util.uuid.RandomUuidGen; 
    621     import tango.sys.Common; 
    622     import tango.scrapple.util.uuid.NativeUuidGen; 
    623     import tango.scrapple.util.uuid.NameUuidGen; 
    624      
    625     import tango.time.Clock; 
    626     //import tango.util.time.Clock; 
    627     import tango.io.Stdout; 
     593debug (UuidStandalone) 
     594
     595    import 
     596        tango.scrapple.util.uuid.NativeUuidGen, 
     597        tango.scrapple.util.uuid.RandomUuidGen, 
     598        tango.scrapple.util.uuid.NameUuidGen; 
    628599 
    629600    void main() 
    630601    { 
    631         auto c = new TimeUuidGen!(Options.Strict | Options.Mac | Options.Shared, 200)(new FileUuidPersister("uuid-state-2")); 
    632         scope (exit) 
    633             c.close(); 
    634  
    635         int j = 1_000_000; 
    636         int i; 
    637         Uuid uuid; 
    638         Stdout("Testing...").newline; 
    639         for (int k = 0; k < 125; k++) 
    640         { 
    641             /+ 
    642             j = 10_000_000; 
    643             auto start = Clock.now; 
    644             while (j--) 
    645             { 
    646                 uuid = newTimeUuid(); 
    647                 //i += uuid.timeLow; 
    648             } 
    649             Stdout(uuid.toString, (Clock.now - start).millis, uuid.ver).newline; 
    650             +/ 
    651  
    652             j = 1_000_000; 
    653             auto start = Clock.now; 
    654             while (j--) 
    655             { 
    656                 uuid = c(); 
    657                 //i += uuid.timeLow; 
    658             } 
    659             Stdout(uuid, (Clock.now - start).millis, uuid.ver).newline.newline; 
    660        } 
    661     } 
    662 
    663  
     602    } 
     603
  • trunk/tango/scrapple/util/uuid/doc/NameUuidGen.html

    r50 r56  
    44    </head><body> 
    55    <h1>tango.scrapple.util.uuid.NameUuidGen</h1> 
    6     <!-- Generated by Ddoc from E:\d-projects\scrapple\tango\scrapple\util\uuid\NameUuidGen.d --> 
     6    <!-- Generated by Ddoc from NameUuidGen.d --> 
    77<b>License:</b><br> 
    88BSD style:  
     
    3131<br><br> 
    3232 
    33 <dl><dt><big>Uuid <u>newUuidSha1</u>(Uuid <i>nsUuid</i>, char[] <i>name</i>); 
     33<dl><dt><big>Uuid <u>newUuidSha1</u>(Uuid <i>nsUuid</i>, char[] <i>name</i>); 
    3434</big></dt> 
    3535<dd>Generates a name-based UUID using SHA-1 hashing algorithm (version 5 UUID). 
     
    4646 
    4747</dd> 
    48 <dt><big>Uuid <u>newUuidMd5</u>(Uuid <i>nsUuid</i>, char[] <i>name</i>); 
     48<dt><big>Uuid <u>newUuidMd5</u>(Uuid <i>nsUuid</i>, char[] <i>name</i>); 
    4949</big></dt> 
    5050<dd>Generates a name-based UUID using MD-5 hashing algorithm (version 3 UUID). 
  • trunk/tango/scrapple/util/uuid/doc/NativeUuidGen.html

    r50 r56  
    44    </head><body> 
    55    <h1>tango.scrapple.util.uuid.NativeUuidGen</h1> 
    6     <!-- Generated by Ddoc from E:\d-projects\scrapple\tango\scrapple\util\uuid\NativeUuidGen.d --> 
     6    <!-- Generated by Ddoc from NativeUuidGen.d --> 
    77<b>License:</b><br> 
    88BSD style:  
     
    2626<br><br> 
    2727 
    28 <dl><dt><big>Uuid <u>newUuid</u>(); 
     28<dl><dt><big>Uuid <u>newUuid</u>(); 
    2929</big></dt> 
    3030<dd>Generates a UUID using the safest method available on the target platform. 
     
    3737 
    3838</dd> 
    39 <dt><big>Uuid <u>newTimeUuid</u>(); 
     39<dt><big>Uuid <u>newTimeUuid</u>(); 
    4040</big></dt> 
    4141<dd>Generates a time-based (version 1) UUID if supported by the target platform. 
  • trunk/tango/scrapple/util/uuid/doc/RandomUuidGen.html

    r50 r56  
    44    </head><body> 
    55    <h1>tango.scrapple.util.uuid.RandomUuidGen</h1> 
    6     <!-- Generated by Ddoc from E:\d-projects\scrapple\tango\scrapple\util\uuid\RandomUuidGen.d --> 
     6    <!-- Generated by Ddoc from RandomUuidGen.d --> 
    77<b>License:</b><br> 
    88BSD style:  
     
    6969</dl> 
    7070</dd> 
    71 <dt><big>const RandomUuidGen!(int(*)()) <u>newUuid</u>; 
     71<dt><big>const RandomUuidGen!(int function()) <u>newUuid</u>; 
    7272</big></dt> 
    7373<dd>Generates a random UUID using the C runtime's random number generator. 
  • trunk/tango/scrapple/util/uuid/doc/Uuid.html

    r50 r56  
    1313<br><br> 
    1414 
    15         This module defines the 128-bit Universally Unique Identifier structure 
     15        This module defines a 128-bit Universally Unique Identifier structure 
    1616        conforming to Proposed Stardard RFC-4122. 
    1717 
     
    3737<dl><dt><big>enum <u>UuidVariant</u>; 
    3838</big></dt> 
    39 <dd>Uuid variants
     39<dd>The UUID variants. The UUID variant determines the layout of the UUID
    4040<br><br> 
    4141 
    4242<dl><dt><big><u>Ncs</u></big></dt> 
    43 <dd><br><br> 
     43<dd>Reserved, NCS backward compatibility. 
     44<br><br> 
     45 
    4446</dd> 
    4547<dt><big><u>Standard</u></big></dt> 
    46 <dd><br><br> 
     48<dd>The UUID is compatible with RFC-4122. 
     49<br><br> 
     50 
    4751</dd> 
    4852<dt><big><u>Microsoft</u></big></dt> 
    49 <dd><br><br> 
     53<dd>Reserved, Microsoft backward compatibility. 
     54<br><br> 
     55 
    5056</dd> 
    5157<dt><big><u>Future</u></big></dt> 
    52 <dd><br><br> 
     58<dd>Reserved for future definition. 
     59<br><br> 
     60 
    5361</dd> 
    5462</dl> 
     
    5664<dt><big>enum <u>UuidVersion</u>; 
    5765</big></dt> 
    58 <dd>Uuid versions
     66<dd>Versions of a standard UUID
    5967<br><br> 
    6068 
    6169<dl><dt><big><u>TimeBased</u></big></dt> 
    62 <dd><br><br> 
     70<dd>The time-based version. 
     71<br><br> 
     72 
    6373</dd> 
    6474<dt><big><u>Dce</u></big></dt> 
    65 <dd><br><br> 
     75<dd>The DCE security version, with embedded POSIX UIDs. 
     76<br><br> 
     77 
    6678</dd> 
    6779<dt><big><u>NameBasedMd5</u></big></dt> 
    68 <dd><br><br> 
     80<dd>The name-based version that uses MD5 hashing. 
     81<br><br> 
     82 
    6983</dd> 
    7084<dt><big><u>Random</u></big></dt> 
    71 <dd><br><br> 
     85<dd>The randomly or pseudo-randomly generated version. 
     86<br><br> 
     87 
    7288</dd> 
    7389<dt><big><u>NameBasedSha1</u></big></dt> 
    74 <dd><br><br> 
     90<dd>The name-based version specified that uses SHA1 hashing. 
     91<br><br> 
     92 
    7593</dd> 
    7694</dl> 
     
    83101<dl><dt><big>uint <u>timeLow</u>; 
    84102</big></dt> 
    85 <dd><br><br> 
     103<dd>The low field of the timestamp. 
     104<br><br> 
     105 
    86106</dd> 
    87107<dt><big>ushort <u>timeMid</u>; 
    88108</big></dt> 
    89 <dd><br><br> 
     109<dd>The middle field of the timestamp. 
     110<br><br> 
     111 
    90112</dd> 
    91113<dt><big>ushort <u>versionTimeHigh</u>; 
    92114</big></dt> 
    93 <dd><br><br> 
     115<dd>The high field of the timestamp multiplexed with the version number. 
     116<br><br> 
     117 
    94118</dd> 
    95119<dt><big>ubyte <u>variantClockSeqHigh</u>; 
    96120</big></dt> 
    97 <dd><br><br> 
     121<dd>The high field of the clock sequence multiplexed with the variant. 
     122<br><br> 
     123 
    98124</dd> 
    99125<dt><big>ubyte <u>clockSeqLow</u>; 
    100126</big></dt> 
    101 <dd><br><br> 
     127<dd>The low field of the clock sequence. 
     128<br><br> 
     129 
    102130</dd> 
    103131<dt><big>ubyte[6u] <u>node</u>; 
    104132</big></dt> 
    105 <dd><br><br> 
     133<dd>The spatially unique <u>node</u> identifier. 
     134<br><br> 
     135 
    106136</dd> 
    107137<dt><big><u>StringLength</u></big></dt> 
    108 <dd>Length of the string representation of a UUID, in UTF-8 characters (36). 
     138<dd>The length of the string representation of a UUID (36 characters). 
    109139         
    110140<br><br> 
     
    142172 
    143173</dd> 
    144 <dt><big>UuidVersion <u>ver</u>(UuidVersion <u>ver</u>); 
     174<dt><big>UuidVersion <u>ver</u>(UuidVersion <i>v</i>); 
    145175</big></dt> 
    146176<dd>Sets the UUID version. 
    147177<br><br> 
    148178<b>Params:</b><br> 
    149 <table><tr><td>UuidVersion <u>ver</u></td> 
     179<table><tr><td>UuidVersion <i>v</i></td> 
    150180<td>UUID version.</td></tr> 
    151181</table><br> 
     
    219249 
    220250</dd> 
    221 <dt><big>Uuid <u>opAssign</u>(char[] <i>str</i>); 
     251<dt><big>Uuid <u>opAssign</u>(char[] <i>str</i>); 
    222252</big></dt> 
    223253<dd>Parses the UUID string and assigns the result to this UUID. 
     
    235265 
    236266</dd> 
    237 <dt><big>Uuid <u>opAssign</u>(ubyte[] <i>octets</i>); 
     267<dt><big>Uuid <u>opAssign</u>(ubyte[] <i>octets</i>); 
    238268</big></dt> 
    239269<dd>Assigns the UUID octets arranged in network byte order to this UUID . 
     
    245275 
    246276</dd> 
    247 <dt><big>static Uuid <u>opCall</u>(uint <i>timeLow</i>, ushort <i>timeMid</i>, ushort <i>versionTimeHigh</i>, ubyte <i>variantClockSeqHigh</i>, ubyte <i>clockSeqLow</i>, ubyte[6u] <i>node</i>); 
     277<dt><big>static Uuid <u>opCall</u>(uint <i>timeLow</i>, ushort <i>timeMid</i>, ushort <i>versionTimeHigh</i>, ubyte <i>variantClockSeqHigh</i>, ubyte <i>clockSeqLow</i>, ubyte[6u] <i>node</i>); 
    248278</big></dt> 
    249279<dd>Creates a UUID from UUID field values. 
     
    252282 
    253283</dd> 
    254 <dt><big>static Uuid <u>opCall</u>(char[] <i>str</i>); 
     284<dt><big>static Uuid <u>opCall</u>(char[] <i>str</i>); 
    255285</big></dt> 
    256286<dd>Creates a new UUID from the supplied string. 
     
    263293 
    264294</dd> 
    265 <dt><big>char[] <u>opCast</u>(); 
    266 </big></dt> 
    267 <dd>Casts the UUID to its string representation. 
    268      
    269 <br><br> 
    270  
    271 </dd> 
    272 <dt><big>static Uuid  <u>opCall</u>(ubyte[] <i>octets</i>); 
     295<dt><big>static Uuid <u>opCall</u>(ubyte[] <i>octets</i>); 
    273296</big></dt> 
    274297<dd>Creates a UUID from octets arranged in network byte order.