text stringlengths 0 15.7k | source stringlengths 6 112 |
|---|---|
if oldBucket is not missing value then -- shallow copy the linked list and add it new newObject's bucket list at the same position | lns3.scpt |
set newBucket to {k:oldBucket's k, v:oldBucket's v, nextItem:missing value} | lns3.scpt |
set item i of newObject's _buckets to newBucket | lns3.scpt |
repeat while nextItem of oldBucket is not missing value | lns3.scpt |
set oldBucket to nextItem of oldBucket | lns3.scpt |
set tmp to {k:oldBucket's k, v:oldBucket's v, nextItem:missing value} | lns3.scpt |
set newBucket's nextItem to tmp | lns3.scpt |
set newBucket to tmp | lns3.scpt |
return newObject | lns3.scpt |
_error("copyObject", eText, eNumber, eFrom, eTo) | lns3.scpt |
end copyObject | lns3.scpt |
to addDictionary(dictionaryObject) | lns3.scpt |
if dictionaryObject's countItems() > 0 then | lns3.scpt |
if length of my _buckets ≠ length of dictionaryObject's _buckets then error "Mismatched bucket lists." -- sanity check, as above | lns3.scpt |
repeat with i from 1 to length of dictionaryObject's _buckets | lns3.scpt |
set otherBucket to item i of dictionaryObject's _buckets | lns3.scpt |
if otherBucket is not missing value then -- transfer other dictionary's bucket… | lns3.scpt |
set myBucket to item i of my _buckets | lns3.scpt |
if myBucket is missing value then -- …by shallow copy | lns3.scpt |
set myBucket to {k:otherBucket's k, v:otherBucket's v, nextItem:missing value} | lns3.scpt |
set item i of my _buckets to myBucket | lns3.scpt |
repeat while nextItem of otherBucket is not missing value | lns3.scpt |
set otherBucket to nextItem of otherBucket | lns3.scpt |
set tmp to {k:otherBucket's k, v:otherBucket's v, nextItem:missing value} | lns3.scpt |
set myBucket's nextItem to tmp | lns3.scpt |
set myBucket to tmp | lns3.scpt |
else -- …by merging into this dictionary's existing bucket | lns3.scpt |
repeat while otherBucket is not missing value | lns3.scpt |
set tmp to myBucket | lns3.scpt |
if tmp's k is otherBucket's k then -- replace | lns3.scpt |
set tmp's {k, v} to otherBucket's {k, v} | lns3.scpt |
else if tmp's nextItem is missing value then -- append | lns3.scpt |
set tmp's nextItem to {k:otherBucket's k, v:otherBucket's v, nextItem:missing value} | lns3.scpt |
set tmp to tmp's nextItem | lns3.scpt |
_error("addDictionary", eText, eNumber, eFrom, eTo) | lns3.scpt |
end addDictionary | lns3.scpt |
to addKeysAndValues(keyValueList) -- list of form {{KEY,VALUE},...} | lns3.scpt |
if (count {keyValueList} each list) = 0 then error "Not a valid key-value list." number -1700 from keyValueList | lns3.scpt |
script listObject | lns3.scpt |
property _list_ : keyValueList | lns3.scpt |
repeat with aRef in listObject's _list_ | lns3.scpt |
set keyValue to aRef's contents | lns3.scpt |
if (count {keyValue} each list) = 0 or keyValue's length ≠ 2 then error number -1700 | lns3.scpt |
addItem(keyValue's item 1, keyValue's item 2) | lns3.scpt |
on error number n | lns3.scpt |
error "Not a valid key-value pair." number n from aRef | lns3.scpt |
_error("addKeysAndValues", eText, eNumber, eFrom, eTo) | lns3.scpt |
end addKeysAndValues | lns3.scpt |
to getKeysAndValues() | lns3.scpt |
repeat with bucketRef in my _buckets | lns3.scpt |
set myBucket to bucketRef's contents | lns3.scpt |
repeat while myBucket is not missing value | lns3.scpt |
copy myBucket's k to k -- make sure date keys are always copied | lns3.scpt |
set end of listObject's _list_ to {k, myBucket's v} | lns3.scpt |
set myBucket to myBucket's nextItem | lns3.scpt |
return listObject's _list_ | lns3.scpt |
end getKeysAndValues | lns3.scpt |
to getKeys() | lns3.scpt |
copy myBucket's k to end of listObject's _list_ -- make sure date keys are always copied | lns3.scpt |
end getKeys | lns3.scpt |
to getValues() | lns3.scpt |
set end of listObject's _list_ to myBucket's v | lns3.scpt |
end getValues | lns3.scpt |
end dictionary collection | lns3.scpt |
to stack collection -- Last-In-First-Out sequence | lns3.scpt |
script StackCollection | lns3.scpt |
property _head : missing value | lns3.scpt |
_support's throwMethodError("Objects", "StackCollection", handlerName, eText, eNumber, eFrom, eTo) | lns3.scpt |
to addItem(theValue) | lns3.scpt |
set _head to {v:theValue, nextItem:_head} | lns3.scpt |
to removeItem() -- remove and return the topmost value | lns3.scpt |
if _head is missing value then error "Stack is empty." number -1728 | lns3.scpt |
set theValue to v of _head | lns3.scpt |
set _head to nextItem of _head | lns3.scpt |
set _head to missing value | lns3.scpt |
to getItem() -- return the topmost value without removing it | lns3.scpt |
return v of _head | lns3.scpt |
return "«stack collection (" & _count & " items)»" | lns3.scpt |
set newObject to stack collection | lns3.scpt |
set newObject's _count to _count | lns3.scpt |
set newHead to {v:_head's v, nextItem:missing value} | lns3.scpt |
set newObject's _head to newHead | lns3.scpt |
set oldHead to _head's nextItem | lns3.scpt |
repeat while oldHead is not missing value | lns3.scpt |
set tmp to {v:oldHead's v, nextItem:missing value} | lns3.scpt |
set newHead's nextItem to tmp | lns3.scpt |
set newHead to tmp | lns3.scpt |
set oldHead to oldHead's nextItem | lns3.scpt |
end stack collection | lns3.scpt |
to queue collection -- First-In-First-Out sequence | lns3.scpt |
script QueueCollection | lns3.scpt |
property _back : missing value | lns3.scpt |
property _front : missing value | lns3.scpt |
_support's throwMethodError("Objects", "QueueCollection", handlerName, eText, eNumber, eFrom, eTo) | lns3.scpt |
set nextItem to {v:theValue, nextItem:missing value} | lns3.scpt |
if _back is not missing value then set nextItem of _back to nextItem | lns3.scpt |
set _back to nextItem | lns3.scpt |
if _front is missing value then set _front to _back | lns3.scpt |
to removeItem() -- remove and return the value at the front of the queue | lns3.scpt |
if _front is missing value then error "Queue is empty." number -1728 | lns3.scpt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.