Changeset 56
- Timestamp:
- 04/03/08 06:48:19 (4 years ago)
- Files:
-
- trunk/tango/scrapple/util/uuid/NameUuidGen.d (modified) (4 diffs)
- trunk/tango/scrapple/util/uuid/NativeUuidGen.d (modified) (1 diff)
- trunk/tango/scrapple/util/uuid/RandomUuidGen.d (modified) (1 diff)
- trunk/tango/scrapple/util/uuid/TimeUuidGen.d (deleted)
- trunk/tango/scrapple/util/uuid/UnitTestUtil.d (deleted)
- trunk/tango/scrapple/util/uuid/Uuid.d (modified) (13 diffs)
- trunk/tango/scrapple/util/uuid/doc/AutoSemaphore.html (deleted)
- trunk/tango/scrapple/util/uuid/doc/IpcObject.html (deleted)
- trunk/tango/scrapple/util/uuid/doc/Mac.html (deleted)
- trunk/tango/scrapple/util/uuid/doc/MappableFile.html (deleted)
- trunk/tango/scrapple/util/uuid/doc/MappedRegion.html (deleted)
- trunk/tango/scrapple/util/uuid/doc/MemoryMappable.html (deleted)
- trunk/tango/scrapple/util/uuid/doc/NameUuidGen.html (modified) (3 diffs)
- trunk/tango/scrapple/util/uuid/doc/NamedSemaphore.html (deleted)
- trunk/tango/scrapple/util/uuid/doc/NativeUuidGen.html (modified) (3 diffs)
- trunk/tango/scrapple/util/uuid/doc/RandomUuidGen.html (modified) (2 diffs)
- trunk/tango/scrapple/util/uuid/doc/SharedMemoryObject.html (deleted)
- trunk/tango/scrapple/util/uuid/doc/SysString.html (deleted)
- trunk/tango/scrapple/util/uuid/doc/TimeUuidGen.html (deleted)
- trunk/tango/scrapple/util/uuid/doc/UnitTestUtil.html (deleted)
- trunk/tango/scrapple/util/uuid/doc/Uuid.html (modified) (10 diffs)
- trunk/tango/scrapple/util/uuid/ipc (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tango/scrapple/util/uuid/NameUuidGen.d
r50 r56 9 9 With the functions in this module, UUIDs can be created from names 10 10 that are unique within a name space. 11 11 12 12 MD-5 or SHA-1 hashing algorithms can be used to generate a name-based UUID. 13 13 If backward compatibility is not an issue, SHA-1 should be preferred. 14 14 15 15 The functions are thread-safe. 16 16 … … 39 39 40 40 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; 43 43 44 44 return uuid; … … 96 96 } 97 97 98 version(UuidUnitTest)98 debug (UuidUnitTest) 99 99 { 100 100 import tango.io.Stdout; … … 125 125 126 126 // 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")); 131 131 132 132 } trunk/tango/scrapple/util/uuid/NativeUuidGen.d
r50 r56 106 106 return uuid; 107 107 } 108 109 debug (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 94 94 const RandomUuidGen!(typeof(&crand)) newUuid = { &crand }; 95 95 96 version(UuidUnitTest)96 debug (UuidUnitTest) 97 97 { 98 98 import tango.math.Random; trunk/tango/scrapple/util/uuid/Uuid.d
r50 r56 7 7 authorS: Max Samukha 8 8 9 This module defines the128-bit Universally Unique Identifier structure9 This module defines a 128-bit Universally Unique Identifier structure 10 10 conforming to Proposed Stardard RFC-4122. 11 11 … … 33 33 import tango.core.Exception; 34 34 35 debug36 {37 import38 tango.io.Stdout,39 tango.io.Console,40 tango.io.FileConduit;41 }42 43 35 private 44 36 { 45 const char[] I NVALID_UUID_STR_MSG= "Invalid UUID string format";46 const char[] D IGITS= "0123456789abcdef";37 const char[] InvalidUuidMsg = "Invalid UUID string format"; 38 const char[] Digits = "0123456789abcdef"; 47 39 } 48 40 … … 62 54 int cCount; 63 55 64 foreach (i, d; D IGITS)56 foreach (i, d; Digits) 65 57 { 66 58 if (d == c1) … … 87 79 assert (hex.length == 2); 88 80 89 hex[0] = D IGITS[ub >> 4];90 hex[1] = D IGITS[ub & 0x0F];81 hex[0] = Digits[ub >> 4]; 82 hex[1] = Digits[ub & 0x0F]; 91 83 } 92 84 93 85 /***************************************************************************************** 94 Uuid variants.86 The UUID variants. The UUID variant determines the layout of the UUID. 95 87 *****************************************************************************************/ 96 88 enum UuidVariant : ubyte 97 89 { 98 /// 90 /// Reserved, NCS backward compatibility. 99 91 Ncs, 100 /// 92 /// The UUID is compatible with RFC-4122. 101 93 Standard, 102 /// 94 /// Reserved, _Microsoft backward compatibility. 103 95 Microsoft, 104 /// 96 /// Reserved for future definition. 105 97 Future 106 98 } 107 99 108 100 /***************************************************************************************** 109 Uuid versions.101 Versions of a standard UUID. 110 102 *****************************************************************************************/ 111 103 enum UuidVersion : ubyte 112 104 { 113 /// 105 /// The time-based version. 114 106 TimeBased = 1, 115 /// 107 /// The DCE security version, with embedded POSIX UIDs. 116 108 Dce = 2, 117 /// 109 /// The name-based version that uses MD5 hashing. 118 110 NameBasedMd5 = 3, 119 /// 111 /// The randomly or pseudo-randomly generated version. 120 112 Random = 4, 121 /// 113 /// The name-based version specified that uses SHA1 hashing. 122 114 NameBasedSha1 = 5 123 115 } … … 130 122 align(1): 131 123 132 /// 124 /// The low field of the timestamp. 133 125 uint timeLow; 134 /// 126 /// The middle field of the timestamp. 135 127 ushort timeMid; 136 /// 128 /// The high field of the timestamp multiplexed with the version number. 137 129 ushort versionTimeHigh; 138 /// 130 /// The high field of the clock sequence multiplexed with the variant. 139 131 ubyte variantClockSeqHigh; 140 /// 132 /// The low field of the clock sequence. 141 133 ubyte clockSeqLow; 142 /// 134 /// The spatially unique node identifier. 143 135 ubyte[6] node; 144 136 … … 146 138 { 147 139 /***************************************************************************************** 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). 149 141 *****************************************************************************************/ 150 142 StringLength = 36 … … 227 219 228 220 Params: 229 v er= UUID version.230 *****************************************************************************************/ 231 UuidVersion ver(UuidVersion v er)221 v = UUID version. 222 *****************************************************************************************/ 223 UuidVersion ver(UuidVersion v) 232 224 { 233 225 versionTimeHigh = (versionTimeHigh & 0x0FFF) | (ver << 12); … … 406 398 str[18] != '-' || str[23] != '-') 407 399 { 408 throw new IllegalArgumentException(I NVALID_UUID_STR_MSG);400 throw new IllegalArgumentException(InvalidUuidMsg); 409 401 } 410 402 … … 422 414 423 415 if (!hexToUbyte(str[cIdx..cIdx + 2], ub)) 424 throw new IllegalArgumentException(I NVALID_UUID_STR_MSG);416 throw new IllegalArgumentException(InvalidUuidMsg); 425 417 426 418 octets[octIdx] = ub; … … 434 426 435 427 return result; 436 }437 438 /*****************************************************************************************439 Casts the UUID to its string representation.440 *****************************************************************************************/441 char[] opCast()442 {443 return toString;444 428 } 445 429 … … 526 510 } 527 511 528 version(UuidUnitTest)512 debug (UuidUnitTest) 529 513 { 530 514 unittest … … 561 545 uuid = testUuidStr; 562 546 assert(uuid.toString == testUuidStr); 563 assert(testUuidStr == cast(char[])uuid);564 547 565 548 ubyte[] octets = uuid.toOctets; … … 608 591 } 609 592 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; 593 debug (UuidStandalone) 594 { 595 import 596 tango.scrapple.util.uuid.NativeUuidGen, 597 tango.scrapple.util.uuid.RandomUuidGen, 598 tango.scrapple.util.uuid.NameUuidGen; 628 599 629 600 void main() 630 601 { 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 4 4 </head><body> 5 5 <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 --> 7 7 <b>License:</b><br> 8 8 BSD style: … … 31 31 <br><br> 32 32 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>); 34 34 </big></dt> 35 35 <dd>Generates a name-based UUID using SHA-1 hashing algorithm (version 5 UUID). … … 46 46 47 47 </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>); 49 49 </big></dt> 50 50 <dd>Generates a name-based UUID using MD-5 hashing algorithm (version 3 UUID). trunk/tango/scrapple/util/uuid/doc/NativeUuidGen.html
r50 r56 4 4 </head><body> 5 5 <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 --> 7 7 <b>License:</b><br> 8 8 BSD style: … … 26 26 <br><br> 27 27 28 <dl><dt><big>Uuid <u>newUuid</u>();28 <dl><dt><big>Uuid <u>newUuid</u>(); 29 29 </big></dt> 30 30 <dd>Generates a UUID using the safest method available on the target platform. … … 37 37 38 38 </dd> 39 <dt><big>Uuid <u>newTimeUuid</u>();39 <dt><big>Uuid <u>newTimeUuid</u>(); 40 40 </big></dt> 41 41 <dd>Generates a time-based (version 1) UUID if supported by the target platform. trunk/tango/scrapple/util/uuid/doc/RandomUuidGen.html
r50 r56 4 4 </head><body> 5 5 <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 --> 7 7 <b>License:</b><br> 8 8 BSD style: … … 69 69 </dl> 70 70 </dd> 71 <dt><big>const RandomUuidGen!(int (*)()) <u>newUuid</u>;71 <dt><big>const RandomUuidGen!(int function()) <u>newUuid</u>; 72 72 </big></dt> 73 73 <dd>Generates a random UUID using the C runtime's random number generator. trunk/tango/scrapple/util/uuid/doc/Uuid.html
r50 r56 13 13 <br><br> 14 14 15 This module defines the128-bit Universally Unique Identifier structure15 This module defines a 128-bit Universally Unique Identifier structure 16 16 conforming to Proposed Stardard RFC-4122. 17 17 … … 37 37 <dl><dt><big>enum <u>UuidVariant</u>; 38 38 </big></dt> 39 <dd> Uuid variants.39 <dd>The UUID variants. The UUID variant determines the layout of the UUID. 40 40 <br><br> 41 41 42 42 <dl><dt><big><u>Ncs</u></big></dt> 43 <dd><br><br> 43 <dd>Reserved, NCS backward compatibility. 44 <br><br> 45 44 46 </dd> 45 47 <dt><big><u>Standard</u></big></dt> 46 <dd><br><br> 48 <dd>The UUID is compatible with RFC-4122. 49 <br><br> 50 47 51 </dd> 48 52 <dt><big><u>Microsoft</u></big></dt> 49 <dd><br><br> 53 <dd>Reserved, Microsoft backward compatibility. 54 <br><br> 55 50 56 </dd> 51 57 <dt><big><u>Future</u></big></dt> 52 <dd><br><br> 58 <dd>Reserved for future definition. 59 <br><br> 60 53 61 </dd> 54 62 </dl> … … 56 64 <dt><big>enum <u>UuidVersion</u>; 57 65 </big></dt> 58 <dd> Uuid versions.66 <dd>Versions of a standard UUID. 59 67 <br><br> 60 68 61 69 <dl><dt><big><u>TimeBased</u></big></dt> 62 <dd><br><br> 70 <dd>The time-based version. 71 <br><br> 72 63 73 </dd> 64 74 <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 66 78 </dd> 67 79 <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 69 83 </dd> 70 84 <dt><big><u>Random</u></big></dt> 71 <dd><br><br> 85 <dd>The randomly or pseudo-randomly generated version. 86 <br><br> 87 72 88 </dd> 73 89 <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 75 93 </dd> 76 94 </dl> … … 83 101 <dl><dt><big>uint <u>timeLow</u>; 84 102 </big></dt> 85 <dd><br><br> 103 <dd>The low field of the timestamp. 104 <br><br> 105 86 106 </dd> 87 107 <dt><big>ushort <u>timeMid</u>; 88 108 </big></dt> 89 <dd><br><br> 109 <dd>The middle field of the timestamp. 110 <br><br> 111 90 112 </dd> 91 113 <dt><big>ushort <u>versionTimeHigh</u>; 92 114 </big></dt> 93 <dd><br><br> 115 <dd>The high field of the timestamp multiplexed with the version number. 116 <br><br> 117 94 118 </dd> 95 119 <dt><big>ubyte <u>variantClockSeqHigh</u>; 96 120 </big></dt> 97 <dd><br><br> 121 <dd>The high field of the clock sequence multiplexed with the variant. 122 <br><br> 123 98 124 </dd> 99 125 <dt><big>ubyte <u>clockSeqLow</u>; 100 126 </big></dt> 101 <dd><br><br> 127 <dd>The low field of the clock sequence. 128 <br><br> 129 102 130 </dd> 103 131 <dt><big>ubyte[6u] <u>node</u>; 104 132 </big></dt> 105 <dd><br><br> 133 <dd>The spatially unique <u>node</u> identifier. 134 <br><br> 135 106 136 </dd> 107 137 <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). 109 139 110 140 <br><br> … … 142 172 143 173 </dd> 144 <dt><big>UuidVersion <u>ver</u>(UuidVersion < u>ver</u>);174 <dt><big>UuidVersion <u>ver</u>(UuidVersion <i>v</i>); 145 175 </big></dt> 146 176 <dd>Sets the UUID version. 147 177 <br><br> 148 178 <b>Params:</b><br> 149 <table><tr><td>UuidVersion < u>ver</u></td>179 <table><tr><td>UuidVersion <i>v</i></td> 150 180 <td>UUID version.</td></tr> 151 181 </table><br> … … 219 249 220 250 </dd> 221 <dt><big>Uuid <u>opAssign</u>(char[] <i>str</i>);251 <dt><big>Uuid <u>opAssign</u>(char[] <i>str</i>); 222 252 </big></dt> 223 253 <dd>Parses the UUID string and assigns the result to this UUID. … … 235 265 236 266 </dd> 237 <dt><big>Uuid <u>opAssign</u>(ubyte[] <i>octets</i>);267 <dt><big>Uuid <u>opAssign</u>(ubyte[] <i>octets</i>); 238 268 </big></dt> 239 269 <dd>Assigns the UUID octets arranged in network byte order to this UUID . … … 245 275 246 276 </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>); 248 278 </big></dt> 249 279 <dd>Creates a UUID from UUID field values. … … 252 282 253 283 </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>); 255 285 </big></dt> 256 286 <dd>Creates a new UUID from the supplied string. … … 263 293 264 294 </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>); 273 296 </big></dt> 274 297 <dd>Creates a UUID from octets arranged in network byte order.
