IF noisy AND (loopCount MOD 100) = 0 THEN out.PutF["...(loopCount %g, number of DIDs %g at %g)...\n", IO.int[loopCount], IO.int[NumberOfKnownDIDs], IO.time[]];
SELECT rand
FROM
IN [0..1) => {
-- volatalize and look up all old dids
lokd: LIST OF DIDStuff;
skipMax: INT ← 1;
skipCnt: INT ← 0;
IF NumberOfKnownDIDs <= 0 THEN LOOP;
SELECT loopCount
FROM
IN [250..500) => skipMax ← RandomChooseInt[randomStream, 1, 3];
IN [500..1000) => skipMax ← RandomChooseInt[randomStream, 1, 7];
IN [1000..2000) => skipMax ← RandomChooseInt[randomStream, 1, 15];
IN [2000..4000) => skipMax ← RandomChooseInt[randomStream, 1, 33];
IN [4000..8000) => skipMax ← RandomChooseInt[randomStream, 1, 67];
IN [8000..16000) => skipMax ← RandomChooseInt[randomStream, 1, 155];
ENDCASE;
IF loopCount = noTests THEN skipMax ← 1;
IF noisy THEN out.PutF["\nStart Look Up All Old Dids, loopCount= %g, skipMax= %g\n", IO.int[loopCount], IO.int[skipMax]];
FOR lokd ← KnownDIDs, lokd.rest
UNTIL lokd =
NIL
DO
skipCnt ← skipCnt + 1;
IF skipCnt >= skipMax THEN skipCnt ← 0 ELSE LOOP;
CheckADID[lokd];
ENDLOOP;
IF noisy THEN out.PutF["Look Up All Old Dids Done\n\n"];
};
IN [1..13) => {
-- make new doc with a contents
rand: INT;
lokd: LIST OF DIDStuff;
newDID: DID;
containerDID: DID ← NIL;
contents: YggRep.TypedPrimitiveElement;
trans: YggTransaction.TransID;
rand ← RandomChooseInt[randomStream, 0, MIN[16384, MAX[0, NumberOfKnownDIDs-2]]];
FOR lokd ← KnownDIDs, lokd.rest
UNTIL lokd =
NIL
DO
rand ← rand - 1;
IF rand <= 0 THEN EXIT;
ENDLOOP;
IF lokd # NIL THEN containerDID ← lokd.first.did;
trans ← YggNav.StartTransaction[YggEnvironment.nullTransID] ;
newDID ← YggNav.CreateObject [trans: trans, containerDID: containerDID, makeRoot: IF lokd = NIL THEN TRUE ELSE FALSE] ;
contents ← MakeUpTPE[];
KnownDIDs ← CONS[[did: newDID, contents: contents, containers: LIST[containerDID]], KnownDIDs];
NumberOfKnownDIDs ← NumberOfKnownDIDs + 1;
YggNav.SetContents[trans: trans, did: newDID, contents: contents];
IF ~YggNav.EndTransaction[trans, TRUE] THEN ERROR;
IF noisy THEN out.PutF["Make new doc: did= %g contents type= %g\n", IO.card[newDID.didLow], IO.card[contents.docType] ];
};
IN [13..19) => {
-- volatalize and look up old did
rand: INT;
lokd: LIST OF DIDStuff;
IF NumberOfKnownDIDs <= 0 THEN LOOP;
rand ← RandomChooseInt[randomStream, 0, MIN[16384, NumberOfKnownDIDs]];
FOR lokd ← KnownDIDs, lokd.rest
UNTIL lokd =
NIL
DO
rand ← rand - 1;
IF rand <= 0 THEN EXIT;
ENDLOOP;
IF lokd = NIL THEN LOOP;
CheckADID[lokd];
IF noisy THEN out.PutF["look up old did: did= %g\n", IO.card[lokd.first.did.didLow] ];
};
IN [19..28) => {
-- add attribute to did
rand: INT;
trans: YggTransaction.TransID;
lokd: LIST OF DIDStuff;
attrName: ROPE;
noAttrVals: INT ;
property: YggRep.Attribute;
fieldTaken: ARRAY [1..5] OF BOOL ← ALL[FALSE];
IF NumberOfKnownDIDs <= 0 THEN LOOP;
rand ← RandomChooseInt[randomStream, 0, MIN[16384, NumberOfKnownDIDs]];
FOR lokd ← KnownDIDs, lokd.rest UNTIL lokd = NIL DO
rand ← rand - 1;
IF rand <= 0 THEN EXIT;
ENDLOOP;
IF lokd = NIL THEN LOOP;
trans ← YggNav.StartTransaction[YggEnvironment.nullTransID] ;
FOR tryNo: INT IN [0..7] DO
propertyNames: LIST OF ROPE;
propExists: BOOL ← FALSE;
rand ← RandomChooseInt[randomStream, 0, 8];
attrName ← attrNameArray[rand];
propertyNames ← YggNav.ListAllProperties[trans: trans, did: lokd.first.did];
FOR lor:
LIST
OF
ROPE ← propertyNames, lor.rest
UNTIL lor =
NIL
DO
IF Rope.Equal[lor.first, attrName]
THEN {
propExists ← TRUE;
EXIT;
};
ENDLOOP;
IF ~propExists THEN EXIT;
attrName ← NIL;
ENDLOOP;
IF attrName = NIL THEN {IF ~YggNav.EndTransaction[trans, TRUE] THEN ERROR; LOOP;};
noAttrVals ← RandomChooseInt[randomStream, 1, 5];
property.value ← NIL;
FOR attrValNo:
INT
IN [0..noAttrVals)
DO
attrVal: YggRep.AttributeValue;
fni: INT;
fni ← RandomChooseInt[randomStream, 1, 5];
IF fieldTaken[fni] THEN LOOP;
fieldTaken[fni] ← TRUE;
attrVal.fieldName ← fieldNameArray[fni];
attrVal.valueSet ← NIL;
FOR tpeNo:
INT
IN [1..fni]
DO
attrVal.valueSet ← CONS[MakeUpTPE[], attrVal.valueSet];
ENDLOOP;
property.value ← CONS[attrVal, property.value];
ENDLOOP;
property.attributeName ← attrName;
YggNav.SetProperty[trans: trans, did: lokd.first.did, propertyName: attrName, property: property, appendProperty: TRUE];
lokd.first.attributes ← CONS[property, lokd.first.attributes];
IF ~YggNav.EndTransaction[trans, TRUE] THEN ERROR;
IF noisy THEN out.PutF["add attribute to old did: did= %g\n", IO.card[lokd.first.did.didLow]];
};
IN [28..32) => {
-- change contents
rand: INT;
contents: YggRep.TypedPrimitiveElement;
trans: YggTransaction.TransID;
lokd: LIST OF DIDStuff;
IF NumberOfKnownDIDs <= 0 THEN LOOP;
rand ← RandomChooseInt[randomStream, 0, MIN[16384, NumberOfKnownDIDs]];
FOR lokd ← KnownDIDs, lokd.rest UNTIL lokd = NIL DO
rand ← rand - 1;
IF rand <= 0 THEN EXIT;
ENDLOOP;
IF lokd = NIL THEN LOOP;
trans ← YggNav.StartTransaction[YggEnvironment.nullTransID] ;
SELECT lokd.first.contents.docType
FROM
YggRep.uninterpretedBytes => {
newSize: CARD ← 0;
bytesMoved: CARD ← 0;
firstByte: CARD ← 0;
lastByte: CARD ← 0;
uBytes: REF YggRep.BitsRep;
gBytes: REF YggRep.BitsRep;
uBytes ← NARROW[lokd.first.contents.bits];
newSize ← RandomChooseInt[randomStream, 8+uBytes.validBytes/2, 8+3*uBytes.validBytes/2];
gBytes ← NEW[YggRep.BitsRep[newSize]];
gBytes.validBytes ← newSize;
FOR byteNo:
CARD
IN [0..
MIN[uBytes.validBytes, gBytes.validBytes])
DO
gBytes.b[byteNo] ← uBytes.b[byteNo];
ENDLOOP;
FOR byteNo:
CARD
IN [
MIN[uBytes.validBytes, gBytes.validBytes]..newSize)
DO
gBytes.b[byteNo] ← RandomChooseInt[randomStream, 1, 255];
ENDLOOP;
IF newSize <= uBytes.validBytes THEN YggNav.SetSize[trans: trans, did: lokd.first.did, size: newSize]
ELSE {
bytesMoved: CARD ← 0;
roundDownFirstByte: CARD ← 0;
roundDownFirstByte ← (uBytes.validBytes/2) * 2;
TRUSTED {bytesMoved ← YggNav.SetUninterpretedContents[trans: trans, did: lokd.first.did, setDocType: FALSE, docType: YggRep.noValue, firstByte: roundDownFirstByte, byteCount: newSize-roundDownFirstByte, from: LOOPHOLE[gBytes, LONG POINTER] + UNITS[YggRep.BitsRep[roundDownFirstByte]]]; };
IF bytesMoved # (newSize - roundDownFirstByte) THEN ERROR;
};
lokd.first.contents.bits ← gBytes;
};
ENDCASE => {
contents ← MakeUpTPE[];
lokd.first.contents ← contents;
YggNav.SetContents[trans: trans, did: lokd.first.did, contents: contents];
};
IF lokd.first.contents.docType # YggNav.GetTypeOfContents[trans: trans, did: lokd.first.did] THEN ERROR;
IF ~YggNav.EndTransaction[trans, TRUE] THEN ERROR;
IF noisy THEN out.PutF["change contents of old did: did= %g, contents type= %g\n", IO.card[lokd.first.did.didLow], IO.card[lokd.first.contents.docType]];
};
IN [32..40) => {
-- add a link
inrand: INT;
outrand: INT;
ctr: INT ← 300;
trans: YggTransaction.TransID;
inlokd: LIST OF DIDStuff;
outlokd: LIST OF DIDStuff;
linkType: ROPE;
linkDID: YggDID.DID;
IF NumberOfKnownDIDs <= 0 THEN LOOP;
inrand ← RandomChooseInt[randomStream, 0, MIN[16384, NumberOfKnownDIDs]];
outrand ← inrand;
WHILE outrand = inrand
AND ctr > 0
DO
outrand ← RandomChooseInt[randomStream, 0, MIN[16384, NumberOfKnownDIDs]];
ctr ← ctr - 1;
ENDLOOP;
IF ctr <= 0 THEN LOOP;
FOR inlokd ← KnownDIDs, inlokd.rest
UNTIL inlokd =
NIL
DO
inrand ← inrand - 1;
IF inrand <= 0 THEN EXIT;
ENDLOOP;
IF inlokd = NIL THEN LOOP;
FOR outlokd ← KnownDIDs, outlokd.rest
UNTIL outlokd =
NIL
DO
outrand ← outrand - 1;
IF outrand <= 0 THEN EXIT;
ENDLOOP;
IF outlokd = NIL THEN LOOP;
IF YggDID.EqualDIDs[outlokd.first.did, inlokd.first.did] THEN LOOP;
linkType ← linkTypes[RandomChooseInt[randomStream, 0, 8]];
trans ← YggNav.StartTransaction[YggEnvironment.nullTransID] ;
linkDID ← YggNav.SnapLink[trans: trans, fromDID: outlokd.first.did, toDID: inlokd.first.did, linkType: linkType];
IF ~YggNav.EndTransaction[trans, TRUE] THEN ERROR;
outlokd.first.outlinks ← CONS[[linkType, linkDID, inlokd.first.did], outlokd.first.outlinks];
inlokd.first.inlinks ← CONS[[linkType, linkDID, outlokd.first.did], inlokd.first.inlinks];
IF noisy THEN out.PutF["add link from %g to %d, type= %g\n", IO.card[outlokd.first.did.didLow], IO.card[inlokd.first.did.didLow], IO.rope[linkType]];
};
ENDCASE;