root / trunk / web / dojo / dojox / uuid / generateTimeBasedUuid.js @ 12
History | View | Annotate | Download (3.87 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.uuid.generateTimeBasedUuid"]){ |
9 |
dojo._hasResource["dojox.uuid.generateTimeBasedUuid"]=true; |
10 |
dojo.provide("dojox.uuid.generateTimeBasedUuid");
|
11 |
dojox.uuid.generateTimeBasedUuid=function(_1){ |
12 |
var _2=dojox.uuid.generateTimeBasedUuid._generator.generateUuidString(_1);
|
13 |
return _2;
|
14 |
}; |
15 |
dojox.uuid.generateTimeBasedUuid.isValidNode=function(_3){ |
16 |
var _4=16; |
17 |
var _5=parseInt(_3,_4);
|
18 |
var _6=dojo.isString(_3)&&_3.length==12&&isFinite(_5); |
19 |
return _6;
|
20 |
}; |
21 |
dojox.uuid.generateTimeBasedUuid.setNode=function(_7){ |
22 |
dojox.uuid.assert((_7===null)||this.isValidNode(_7)); |
23 |
this._uniformNode=_7;
|
24 |
}; |
25 |
dojox.uuid.generateTimeBasedUuid.getNode=function(){ |
26 |
return this._uniformNode; |
27 |
}; |
28 |
dojox.uuid.generateTimeBasedUuid._generator=new function(){ |
29 |
this.GREGORIAN_CHANGE_OFFSET_IN_HOURS=3394248; |
30 |
var _8=null; |
31 |
var _9=null; |
32 |
var _a=null; |
33 |
var _b=0; |
34 |
var _c=null; |
35 |
var _d=null; |
36 |
var _e=16; |
37 |
function _f(_10){ |
38 |
_10[2]+=_10[3]>>>16; |
39 |
_10[3]&=65535; |
40 |
_10[1]+=_10[2]>>>16; |
41 |
_10[2]&=65535; |
42 |
_10[0]+=_10[1]>>>16; |
43 |
_10[1]&=65535; |
44 |
dojox.uuid.assert((_10[0]>>>16)===0); |
45 |
}; |
46 |
function _11(x){ |
47 |
var _12=new Array(0,0,0,0); |
48 |
_12[3]=x%65536; |
49 |
x-=_12[3];
|
50 |
x/=65536;
|
51 |
_12[2]=x%65536; |
52 |
x-=_12[2];
|
53 |
x/=65536;
|
54 |
_12[1]=x%65536; |
55 |
x-=_12[1];
|
56 |
x/=65536;
|
57 |
_12[0]=x;
|
58 |
return _12;
|
59 |
}; |
60 |
function _13(_14,_15){ |
61 |
dojox.uuid.assert(dojo.isArray(_14)); |
62 |
dojox.uuid.assert(dojo.isArray(_15)); |
63 |
dojox.uuid.assert(_14.length==4);
|
64 |
dojox.uuid.assert(_15.length==4);
|
65 |
var _16=new Array(0,0,0,0); |
66 |
_16[3]=_14[3]+_15[3]; |
67 |
_16[2]=_14[2]+_15[2]; |
68 |
_16[1]=_14[1]+_15[1]; |
69 |
_16[0]=_14[0]+_15[0]; |
70 |
_f(_16); |
71 |
return _16;
|
72 |
}; |
73 |
function _17(_18,_19){ |
74 |
dojox.uuid.assert(dojo.isArray(_18)); |
75 |
dojox.uuid.assert(dojo.isArray(_19)); |
76 |
dojox.uuid.assert(_18.length==4);
|
77 |
dojox.uuid.assert(_19.length==4);
|
78 |
var _1a=false; |
79 |
if(_18[0]*_19[0]!==0){ |
80 |
_1a=true;
|
81 |
} |
82 |
if(_18[0]*_19[1]!==0){ |
83 |
_1a=true;
|
84 |
} |
85 |
if(_18[0]*_19[2]!==0){ |
86 |
_1a=true;
|
87 |
} |
88 |
if(_18[1]*_19[0]!==0){ |
89 |
_1a=true;
|
90 |
} |
91 |
if(_18[1]*_19[1]!==0){ |
92 |
_1a=true;
|
93 |
} |
94 |
if(_18[2]*_19[0]!==0){ |
95 |
_1a=true;
|
96 |
} |
97 |
dojox.uuid.assert(!_1a); |
98 |
var _1b=new Array(0,0,0,0); |
99 |
_1b[0]+=_18[0]*_19[3]; |
100 |
_f(_1b); |
101 |
_1b[0]+=_18[1]*_19[2]; |
102 |
_f(_1b); |
103 |
_1b[0]+=_18[2]*_19[1]; |
104 |
_f(_1b); |
105 |
_1b[0]+=_18[3]*_19[0]; |
106 |
_f(_1b); |
107 |
_1b[1]+=_18[1]*_19[3]; |
108 |
_f(_1b); |
109 |
_1b[1]+=_18[2]*_19[2]; |
110 |
_f(_1b); |
111 |
_1b[1]+=_18[3]*_19[1]; |
112 |
_f(_1b); |
113 |
_1b[2]+=_18[2]*_19[3]; |
114 |
_f(_1b); |
115 |
_1b[2]+=_18[3]*_19[2]; |
116 |
_f(_1b); |
117 |
_1b[3]+=_18[3]*_19[3]; |
118 |
_f(_1b); |
119 |
return _1b;
|
120 |
}; |
121 |
function _1c(_1d,_1e){ |
122 |
while(_1d.length<_1e){
|
123 |
_1d="0"+_1d;
|
124 |
} |
125 |
return _1d;
|
126 |
}; |
127 |
function _1f(){ |
128 |
var _20=Math.floor((Math.random()%1)*Math.pow(2,32)); |
129 |
var _21=_20.toString(_e);
|
130 |
while(_21.length<8){ |
131 |
_21="0"+_21;
|
132 |
} |
133 |
return _21;
|
134 |
}; |
135 |
this.generateUuidString=function(_22){ |
136 |
if(_22){
|
137 |
dojox.uuid.assert(dojox.uuid.generateTimeBasedUuid.isValidNode(_22)); |
138 |
}else{
|
139 |
if(dojox.uuid.generateTimeBasedUuid._uniformNode){
|
140 |
_22=dojox.uuid.generateTimeBasedUuid._uniformNode; |
141 |
}else{
|
142 |
if(!_8){
|
143 |
var _23=32768; |
144 |
var _24=Math.floor((Math.random()%1)*Math.pow(2,15)); |
145 |
var _25=(_23|_24).toString(_e);
|
146 |
_8=_25+_1f(); |
147 |
} |
148 |
_22=_8; |
149 |
} |
150 |
} |
151 |
if(!_9){
|
152 |
var _26=32768; |
153 |
var _27=Math.floor((Math.random()%1)*Math.pow(2,14)); |
154 |
_9=(_26|_27).toString(_e); |
155 |
} |
156 |
var now=new Date(); |
157 |
var _28=now.valueOf();
|
158 |
var _29=_11(_28);
|
159 |
if(!_c){
|
160 |
var _2a=_11(60*60); |
161 |
var _2b=_11(dojox.uuid.generateTimeBasedUuid._generator.GREGORIAN_CHANGE_OFFSET_IN_HOURS);
|
162 |
var _2c=_17(_2b,_2a);
|
163 |
var _2d=_11(1000); |
164 |
_c=_17(_2c,_2d); |
165 |
_d=_11(10000);
|
166 |
} |
167 |
var _2e=_29;
|
168 |
var _2f=_13(_c,_2e);
|
169 |
var _30=_17(_2f,_d);
|
170 |
if(now.valueOf()==_a){
|
171 |
_30[3]+=_b;
|
172 |
_f(_30); |
173 |
_b+=1;
|
174 |
if(_b==10000){ |
175 |
while(now.valueOf()==_a){
|
176 |
now=new Date();
|
177 |
} |
178 |
} |
179 |
}else{
|
180 |
_a=now.valueOf(); |
181 |
_b=1;
|
182 |
} |
183 |
var _31=_30[2].toString(_e); |
184 |
var _32=_30[3].toString(_e); |
185 |
var _33=_1c(_31,4)+_1c(_32,4); |
186 |
var _34=_30[1].toString(_e); |
187 |
_34=_1c(_34,4);
|
188 |
var _35=_30[0].toString(_e); |
189 |
_35=_1c(_35,3);
|
190 |
var _36="-"; |
191 |
var _37="1"; |
192 |
var _38=_33+_36+_34+_36+_37+_35+_36+_9+_36+_22;
|
193 |
_38=_38.toLowerCase(); |
194 |
return _38;
|
195 |
}; |
196 |
}(); |
197 |
} |