[Dojo-checkins] ttrenka - r3589 - in trunk: src src/collections
src/crypto tests/collections
dojo-checkins-admin at dojotoolkit.org
dojo-checkins-admin at dojotoolkit.org
Mon Apr 17 15:09:08 MDT 2006
Author: ttrenka
Date: Mon Apr 17 15:09:07 2006
New Revision: 3589
Removed:
trunk/src/crypto/SHA.js
Modified:
trunk/src/collections/ArrayList.js
trunk/src/collections/BinaryTree.js
trunk/src/collections/Collections.js
trunk/src/collections/Dictionary.js
trunk/src/collections/Graph.js
trunk/src/collections/List.js
trunk/src/collections/Queue.js
trunk/src/collections/Set.js
trunk/src/collections/SkipList.js
trunk/src/collections/SortedList.js
trunk/src/collections/Stack.js
trunk/src/crypto/Rijndael.js
trunk/src/crypto/SHA1.js
trunk/src/crypto/SHA256.js
trunk/src/svg.js
trunk/tests/collections/test_Dictionary.html
Log:
Rewrote the Iterator code to use get() and atEnd(); modified all collections to use new iterator code. Testing only completed on Dictionary but passes with flying colors; tested against n elements, 0 elements and 1 element collections.
Added dojo.experimental marks, and removed dojo.crypto.SHA.js.
Note that I'm still testing code.
Modified: trunk/src/collections/ArrayList.js
==============================================================================
--- trunk/src/collections/ArrayList.js (original)
+++ trunk/src/collections/ArrayList.js Mon Apr 17 15:09:07 2006
@@ -1,91 +1,136 @@
dojo.provide("dojo.collections.ArrayList");
dojo.require("dojo.collections.Collections");
-dojo.collections.ArrayList = function(arr){
- var items = [];
- if (arr) items = items.concat(arr);
- this.count = items.length;
- this.add = function(obj){
+dojo.collections.ArrayList=function(/* array? */arr){
+ // summary
+ // Returns a new object of type dojo.collections.ArrayList
+ var items=[];
+ if(arr) items=items.concat(arr);
+ this.count=items.length;
+ this.add=function(/* object */obj){
+ // summary
+ // Add an element to the collection.
items.push(obj);
- this.count = items.length;
+ this.count=items.length;
};
- this.addRange = function(a){
- if (a.getIterator) {
- var e = a.getIterator();
- while (!e.atEnd) {
- this.add(e.current);
- e.moveNext();
+ this.addRange=function(/* array */a){
+ // summary
+ // Add a range of objects to the ArrayList
+ if(a.getIterator){
+ var e=a.getIterator();
+ while(!e.atEnd()){
+ this.add(e.get());
}
- this.count = items.length;
- } else {
- for (var i=0; i<a.length; i++){
+ this.count=items.length;
+ }else{
+ for(var i=0; i<a.length; i++){
items.push(a[i]);
}
- this.count = items.length;
+ this.count=items.length;
}
};
- this.clear = function(){
+ this.clear=function(){
+ // summary
+ // Clear all elements out of the collection, and reset the count.
items.splice(0, items.length);
- this.count = 0;
- };
- this.clone = function(){
- return new dojo.collections.ArrayList(items);
+ this.count=0;
};
- this.contains = function(obj){
- for (var i = 0; i < items.length; i++){
- if (items[i] == obj) {
- return true;
+ this.clone=function(){
+ // summary
+ // Clone the array list
+ return new dojo.collections.ArrayList(items); // dojo.collections.ArrayList
+ };
+ this.contains=function(/* object */obj){
+ // summary
+ // Check to see if the passed object is a member in the ArrayList
+ for(var i=0; i < items.length; i++){
+ if(items[i] == obj) {
+ return true; // bool
}
}
- return false;
+ return false; // bool
};
- this.getIterator = function(){
- return new dojo.collections.Iterator(items);
+ this.forEach=function(/* function */ fn, /* object? */ scope){
+ // summary
+ // functional iterator, following the mozilla spec.
+ var s=scope||dj_global;
+ if(Array.forEach){
+ Array.forEach(items, fn, s);
+ }else{
+ for(var i=0; i<items.length; i++){
+ fn.call(s, items[i], i, items);
+ }
+ }
};
- this.indexOf = function(obj){
- for (var i = 0; i < items.length; i++){
- if (items[i] == obj) {
- return i;
+ this.getIterator=function(){
+ // summary
+ // Get an Iterator for this object
+ return new dojo.collections.Iterator(items); // dojo.collections.Iterator
+ };
+ this.indexOf=function(/* object */obj){
+ // summary
+ // Return the numeric index of the passed object; will return -1 if not found.
+ for(var i=0; i < items.length; i++){
+ if(items[i] == obj) {
+ return i; // int
}
}
- return -1;
+ return -1; // int
};
- this.insert = function(i, obj){
+ this.insert=function(/* int */ i, /* object */ obj){
+ // summary
+ // Insert the passed object at index i
items.splice(i,0,obj);
- this.count = items.length;
- };
- this.item = function(k){
- return items[k];
+ this.count=items.length;
};
- this.remove = function(obj){
- var i = this.indexOf(obj);
- if (i >=0) {
+ this.item=function(/* int */ i){
+ // summary
+ // return the element at index i
+ return items[i]; // object
+ };
+ this.remove=function(/* object */obj){
+ // summary
+ // Look for the passed object, and if found, remove it from the internal array.
+ var i=this.indexOf(obj);
+ if(i >=0) {
items.splice(i,1);
}
- this.count = items.length;
+ this.count=items.length;
};
- this.removeAt = function(i){
+ this.removeAt=function(/* int */ i){
+ // summary
+ // return an array with function applied to all elements
items.splice(i,1);
- this.count = items.length;
+ this.count=items.length;
};
- this.reverse = function(){
+ this.reverse=function(){
+ // summary
+ // Reverse the internal array
items.reverse();
};
- this.sort = function(fn){
- if (fn){
+ this.sort=function(/* function? */ fn){
+ // summary
+ // sort the internal array
+ if(fn){
items.sort(fn);
- } else {
+ }else{
items.sort();
}
};
- this.setByIndex = function(i, obj){
+ this.setByIndex=function(/* int */ i, /* object */ obj){
+ // summary
+ // Set an element in the array by the passed index.
items[i]=obj;
this.count=items.length;
};
- this.toArray = function(){
+ this.toArray=function(){
+ // summary
+ // Return a new array with all of the items of the internal array concatenated.
return [].concat(items);
}
- this.toString = function(){
- return items.join(",");
+ this.toString=function(/* string */ delim){
+ // summary
+ // implementation of toString, follows [].toString();
+ return items.join((delim||","));
};
};
Modified: trunk/src/collections/BinaryTree.js
==============================================================================
--- trunk/src/collections/BinaryTree.js (original)
+++ trunk/src/collections/BinaryTree.js Mon Apr 17 15:09:07 2006
@@ -1,24 +1,26 @@
dojo.provide("dojo.collections.BinaryTree");
dojo.require("dojo.collections.Collections");
-dojo.collections.BinaryTree = function(data){
+dojo.experimental("dojo.collections.BinaryTree");
+
+dojo.collections.BinaryTree=function(data){
function node(data, rnode, lnode){
- this.value = data || null;
- this.right = rnode || null;
- this.left = lnode || null;
- this.clone = function(){
- var c = new node();
- if (this.value.value) c.value = this.value.clone();
- else c.value = this.value;
- if (this.left) c.left = this.left.clone();
- if (this.right) c.right = this.right.clone();
+ this.value=data||null;
+ this.right=rnode||null;
+ this.left=lnode||null;
+ this.clone=function(){
+ var c=new node();
+ if (this.value.value) c.value=this.value.clone();
+ else c.value=this.value;
+ if (this.left) c.left=this.left.clone();
+ if (this.right) c.right=this.right.clone();
}
- this.compare = function(n){
+ this.compare=function(n){
if (this.value > n.value) return 1;
if (this.value < n.value) return -1;
return 0;
}
- this.compareData = function(d){
+ this.compareData=function(d){
if (this.value > d) return 1;
if (this.value < d) return -1;
return 0;
@@ -34,27 +36,27 @@
}
function preorderTraversal(current, sep){
- var s = "";
+ var s="";
if (current){
- s = current.value.toString() + sep;
+ s=current.value.toString() + sep;
s += preorderTraversal(current.left, sep);
s += preorderTraversal(current.right, sep);
}
return s;
}
function inorderTraversal(current, sep){
- var s = "";
+ var s="";
if (current){
- s = inorderTraversal(current.left, sep);
+ s=inorderTraversal(current.left, sep);
s += current.value.toString() + sep;
s += inorderTraversal(current.right, sep);
}
return s;
}
function postorderTraversal(current, sep){
- var s = "";
+ var s="";
if (current){
- s = postorderTraversal(current.left, sep);
+ s=postorderTraversal(current.left, sep);
s += postorderTraversal(current.right, sep);
s += current.value.toString() + sep;
}
@@ -63,127 +65,127 @@
function searchHelper(current, data){
if (!current) return null;
- var i = current.compareData(data);
+ var i=current.compareData(data);
if (i == 0) return current;
if (result > 0) return searchHelper(current.left, data);
else return searchHelper(current.right, data);
}
- this.add = function(data){
- var n = new node(data);
+ this.add=function(data){
+ var n=new node(data);
var i;
- var current = root;
- var parent = null;
+ var current=root;
+ var parent=null;
while (current){
- i = current.compare(n);
+ i=current.compare(n);
if (i == 0) return;
- parent = current;
- if (i > 0) current = current.left;
- else current = current.right;
+ parent=current;
+ if (i > 0) current=current.left;
+ else current=current.right;
}
this.count++;
- if (!parent) root = n;
+ if (!parent) root=n;
else {
- i = parent.compare(n);
- if (i > 0) parent.left = n;
- else parent.right = n;
+ i=parent.compare(n);
+ if (i > 0) parent.left=n;
+ else parent.right=n;
}
};
- this.clear = function(){
- root = null;
- this.count = 0;
- };
- this.clone = function(){
- var c = new dojo.collections.BinaryTree();
- c.root = root.clone();
- c.count = this.count;
+ this.clear=function(){
+ root=null;
+ this.count=0;
+ };
+ this.clone=function(){
+ var c=new dojo.collections.BinaryTree();
+ c.root=root.clone();
+ c.count=this.count;
return c;
};
- this.contains = function(data){
+ this.contains=function(data){
return this.search(data) != null;
};
- this.deleteData = function(data){
- var current = root;
- var parent = null;
- var i = current.compareData(data);
+ this.deleteData=function(data){
+ var current=root;
+ var parent=null;
+ var i=current.compareData(data);
while (i != 0 && current != null){
if (i > 0){
- parent = current;
- current = current.left;
+ parent=current;
+ current=current.left;
} else if (i < 0) {
- parent = current;
- current = current.right;
+ parent=current;
+ current=current.right;
}
- i = current.compareData(data);
+ i=current.compareData(data);
}
if (!current) return;
this.count--;
if (!current.right) {
- if (!parent) root = current.left;
+ if (!parent) root=current.left;
else {
- i = parent.compare(current);
- if (i > 0) parent.left = current.left;
- else if (i < 0) parent.right = current.left;
+ i=parent.compare(current);
+ if (i > 0) parent.left=current.left;
+ else if (i < 0) parent.right=current.left;
}
} else if (!current.right.left){
- if (!parent) root = current.right;
+ if (!parent) root=current.right;
else {
- i = parent.compare(current);
- if (i > 0) parent.left = current.right;
- else if (i < 0) parent.right = current.right;
+ i=parent.compare(current);
+ if (i > 0) parent.left=current.right;
+ else if (i < 0) parent.right=current.right;
}
} else {
- var leftmost = current.right.left;
- var lmParent = current.right;
+ var leftmost=current.right.left;
+ var lmParent=current.right;
while (leftmost.left != null){
- lmParent = leftmost;
- leftmost = leftmost.left;
+ lmParent=leftmost;
+ leftmost=leftmost.left;
}
- lmParent.left = leftmost.right;
- leftmost.left = current.left;
- leftmost.right = current.right;
- if (!parent) root = leftmost;
+ lmParent.left=leftmost.right;
+ leftmost.left=current.left;
+ leftmost.right=current.right;
+ if (!parent) root=leftmost;
else {
- i = parent.compare(current);
- if (i > 0) parent.left = leftmost;
- else if (i < 0) parent.right = leftmost;
+ i=parent.compare(current);
+ if (i > 0) parent.left=leftmost;
+ else if (i < 0) parent.right=leftmost;
}
}
};
- this.getIterator = function(){
- var a = new ArrayList();
+ this.getIterator=function(){
+ var a=[];
inorderTraversalBuildup(root, a);
- return a.getIterator();
+ return new dojo.collections.Iterator(a);
};
- this.search = function(data){
+ this.search=function(data){
return searchHelper(root, data);
};
- this.toString = function(order, sep){
- if (!order) var order = dojo.collections.BinaryTree.TraversalMethods.Inorder;
- if (!sep) var sep = " ";
- var s = "";
+ this.toString=function(order, sep){
+ if (!order) var order=dojo.collections.BinaryTree.TraversalMethods.Inorder;
+ if (!sep) var sep=" ";
+ var s="";
switch (order){
case dojo.collections.BinaryTree.TraversalMethods.Preorder:
- s = preorderTraversal(root, sep);
+ s=preorderTraversal(root, sep);
break;
case dojo.collections.BinaryTree.TraversalMethods.Inorder:
- s = inorderTraversal(root, sep);
+ s=inorderTraversal(root, sep);
break;
case dojo.collections.BinaryTree.TraversalMethods.Postorder:
- s = postorderTraversal(root, sep);
+ s=postorderTraversal(root, sep);
break;
};
if (s.length == 0) return "";
else return s.substring(0, s.length - sep.length);
};
- this.count = 0;
- var root = this.root = null;
+ this.count=0;
+ var root=this.root=null;
if (data) {
this.add(data);
}
}
-dojo.collections.BinaryTree.TraversalMethods = {
+dojo.collections.BinaryTree.TraversalMethods={
Preorder : 0,
Inorder : 1,
Postorder : 2
Modified: trunk/src/collections/Collections.js
==============================================================================
--- trunk/src/collections/Collections.js (original)
+++ trunk/src/collections/Collections.js Mon Apr 17 15:09:07 2006
@@ -1,66 +1,124 @@
dojo.provide("dojo.collections.Collections");
-dojo.collections = {Collections:true};
-dojo.collections.DictionaryEntry = function(k,v){
- this.key = k;
- this.value = v;
- this.valueOf = function(){ return this.value; };
- this.toString = function(){ return this.value; };
+dojo.collections={Collections:true};
+dojo.collections.DictionaryEntry=function(/* string */k, /* object */v){
+ // summary
+ // return an object of type dojo.collections.DictionaryEntry
+ this.key=k;
+ this.value=v;
+ this.valueOf=function(){
+ return this.value; // object
+ };
+ this.toString=function(){
+ return String(this.value); // string
+ };
}
-dojo.collections.Iterator = function(a){
- var obj = a;
- var position = 0;
- this.atEnd = (position>=obj.length-1);
- this.current = obj[position];
- this.moveNext = function(){
- if(++position>=obj.length){
- this.atEnd = true;
+/* Iterators
+ * The collections.Iterators (Iterator and DictionaryIterator) are built to
+ * work with the Collections included in this namespace. However, they *can*
+ * be used with arrays and objects, respectively, should one choose to do so.
+ *
+ * Usage:
+ * var e=new dojo.collection.Iterator(myArray);
+ * while(e.current()) doSomething(e.element);
+ * OR
+ * while(!e.atEnd()) doSomething(e.current());
+ * OR
+ * for(e.current();!e.atEnd();e.current()) doSomething(e.element);
+ * OR
+ * do{ doSomething(e.element); }while(e.current());
+ * OR
+ * (new dojo.collections.Iterator(myArray)).map(doSomething);
+ */
+dojo.collections.Iterator=function(/* array */arr){
+ // summary
+ // return an object of type dojo.collections.Iterator
+ var a=arr;
+ var position=0;
+ this.element=a[position]||null;
+ this.atEnd=function(){
+ // summary
+ // Test to see if the internal cursor has reached the end of the internal collection.
+ return (position>=a.length); // bool
+ };
+ this.get=function(){
+ // summary
+ // Test to see if the internal cursor has reached the end of the internal collection.
+ if(this.atEnd()){
+ return null; // object
}
- if(this.atEnd){
- return false;
+ this.element=a[position++];
+ return this.element; // object
+ };
+ this.map=function(/* function */fn, /* object? */scope){
+ // summary
+ // Functional iteration with optional scope.
+ var s=scope||dj_global;
+ if(Array.map){
+ return Array.map(a,fn,s); // array
+ }else{
+ var arr=[];
+ for(var i=0; i<a.length; i++){
+ arr.push(fn.call(s,a[i]));
+ }
+ return arr; // array
}
- this.current=obj[position];
- return true;
- }
- this.reset = function(){
- position = 0;
- this.atEnd = false;
- this.current = obj[position];
- }
+ };
+ this.reset=function(){
+ // summary
+ // reset the internal cursor.
+ position=0;
+ this.element=a[position];
+ };
}
-dojo.collections.DictionaryIterator = function(obj){
- var arr = [] ; // Create an indexing array
- for (var p in obj) {
- arr.push(obj[p]); // fill it up
+/* Notes:
+ * The DictionaryIterator no longer supports a key and value property;
+ * the reality is that you can use this to iterate over a JS object
+ * being used as a hashtable.
+ */
+dojo.collections.DictionaryIterator=function(/* object */obj){
+ // summary
+ // return an object of type dojo.collections.DictionaryIterator
+ var a=[]; // Create an indexing array
+ for(var p in obj) {
+ a.push(obj[p]); // fill it up
}
- var position = 0 ;
- this.atEnd = (position>=arr.length-1);
- this.current = arr[position]||null ;
- this.entry = this.current||null ;
- this.key = (this.entry)?this.entry.key:null ;
- this.value = (this.entry)?this.entry.value:null ;
- this.moveNext = function() {
- if (++position>=arr.length) {
- this.atEnd = true ;
- }
- if(this.atEnd){
- return false;
+ var position=0;
+ this.element=a[position]||null;
+ this.atEnd=function(){
+ // summary
+ // Test to see if the internal cursor has reached the end of the internal collection.
+ return (position>=a.length); // bool
+ };
+ this.get=function(){
+ // summary
+ // Test to see if the internal cursor has reached the end of the internal collection.
+ if(this.atEnd()){
+ return null; // object
}
- this.entry = this.current = arr[position] ;
- if (this.entry) {
- this.key = this.entry.key ;
- this.value = this.entry.value ;
+ this.element=a[position++];
+ return this.element; // object
+ };
+ this.map=function(/* function */fn, /* object? */scope){
+ // summary
+ // Functional iteration with optional scope.
+ var s=scope||dj_global;
+ if(Array.map){
+ return Array.map(a,fn,s); // array
+ }else{
+ var arr=[];
+ for(var i=0; i<a.length; i++){
+ arr.push(fn.call(s,a[i].value));
+ }
+ return arr; // array
}
- return true;
- } ;
- this.reset = function() {
- position = 0 ;
- this.atEnd = false ;
- this.current = arr[position]||null ;
- this.entry = this.current||null ;
- this.key = (this.entry)?this.entry.key:null ;
- this.value = (this.entry)?this.entry.value:null ;
- } ;
+ };
+ this.reset=function() {
+ // summary
+ // reset the internal cursor.
+ position=0;
+ this.element=a[position];
+ };
};
Modified: trunk/src/collections/Dictionary.js
==============================================================================
--- trunk/src/collections/Dictionary.js (original)
+++ trunk/src/collections/Dictionary.js Mon Apr 17 15:09:07 2006
@@ -1,69 +1,111 @@
dojo.provide("dojo.collections.Dictionary");
dojo.require("dojo.collections.Collections");
-dojo.collections.Dictionary = function(dictionary){
- var items = {};
- this.count = 0;
+dojo.collections.Dictionary=function(/* dojo.collections.Dictionary? */dictionary){
+ // summary
+ // Returns an object of type dojo.collections.Dictionary
+ var items={};
+ this.count=0;
- this.add = function(k,v){
- items[k] = new dojo.collections.DictionaryEntry(k,v);
- this.count++;
- };
- this.clear = function(){
- items = {};
- this.count = 0;
- };
- this.clone = function(){
- return new dojo.collections.Dictionary(this);
- };
- this.contains = this.containsKey = function(k){
- return (items[k] != null);
- };
- this.containsValue = function(v){
- var e = this.getIterator();
- while (!e.atEnd) {
- if (e.value == v) return true;
- e.moveNext();
- }
- return false;
- };
- this.entry=function(k){
- return items[k];
- };
- this.getKeyList = function(){
- var arr = [];
- var e = this.getIterator();
- while (!e.atEnd) {
- arr.push(e.key);
- e.moveNext();
- }
- return arr;
- };
- this.getValueList = function(){
- var arr = [];
- var e = this.getIterator();
- while (!e.atEnd) {
- arr.push(e.value);
- e.moveNext();
- }
- return arr;
- };
- this.item = function(k){
- return items[k].valueOf();
- };
- this.getIterator = function(){
- return new dojo.collections.DictionaryIterator(items);
- };
- this.remove = function(k){
- delete items[k];
- this.count--;
+ this.add=function(/* string */k, /* object */v){
+ // summary
+ // Add a new item to the Dictionary.
+ var b=(k in items);
+ items[k]=new dojo.collections.DictionaryEntry(k,v);
+ if(!b){
+ this.count++;
+ }
+ };
+ this.clear=function(){
+ // summary
+ // Clears the internal dictionary.
+ items={};
+ this.count=0;
+ };
+ this.clone=function(){
+ // summary
+ // Returns a new instance of dojo.collections.Dictionary; note the the dictionary is a clone but items might not be.
+ return new dojo.collections.Dictionary(this); // dojo.collections.Dictionary
+ };
+ this.contains=this.containsKey=function(/* string */k){
+ // summary
+ // Check to see if the dictionary has an entry at key "k".
+ return (items[k]!=null); // bool
+ };
+ this.containsValue=function(/* object */v){
+ // summary
+ // Check to see if the dictionary has an entry with value "v".
+ var e=this.getIterator();
+ while(e.get()){
+ if(e.element.value==v){
+ return true; // bool
+ }
+ }
+ return false; // bool
+ };
+ this.entry=function(/* string */k){
+ // summary
+ // Accessor method; similar to dojo.collections.Dictionary.item but returns the actual Entry object.
+ return items[k]; // dojo.collections.DictionaryEntry
+ };
+ this.forEach=function(/* function */ fn, /* object? */ scope){
+ // summary
+ // functional iterator, following the mozilla spec.
+ var a=[]; // Create an indexing array
+ for(var p in items) {
+ a.push(items[p]); // fill it up
+ }
+ var s=scope||dj_global;
+ if(Array.forEach){
+ Array.forEach(a, fn, s);
+ }else{
+ for(var i=0; i<a.length; i++){
+ fn.call(s, a[i], i, a);
+ }
+ }
+ };
+ this.getKeyList=function(){
+ // summary
+ // Returns an array of the keys in the dictionary.
+ return (this.getIterator()).map(function(e){
+ return e.key;
+ }); // array
+ };
+ this.getValueList=function(){
+ // summary
+ // Returns an array of the values in the dictionary.
+ return (this.getIterator()).map(function(e){
+ return e.value;
+ }); // array
+ };
+ this.item=function(/* string */k){
+ // summary
+ // Accessor method.
+ if(k in items){
+ return items[k].valueOf(); // object
+ }
+ return undefined; // object
+ };
+ this.getIterator=function(){
+ // summary
+ // Gets a dojo.collections.DictionaryIterator for iteration purposes.
+ return new dojo.collections.DictionaryIterator(items); // dojo.collections.DictionaryIterator
+ };
+ this.remove=function(/* string */k){
+ // summary
+ // Removes the item at k from the internal collection.
+ if(k in items){
+ delete items[k];
+ this.count--;
+ return true; // bool
+ }
+ return false; // bool
};
if (dictionary){
- var e = dictionary.getIterator();
- while (!e.atEnd) {
- this.add(e.key, e.value);
- e.moveNext();
+ var e=dictionary.getIterator();
+ while(e.get()) {
+ this.add(e.element.key, e.element.value);
}
}
};
Modified: trunk/src/collections/Graph.js
==============================================================================
--- trunk/src/collections/Graph.js (original)
+++ trunk/src/collections/Graph.js Mon Apr 17 15:09:07 2006
@@ -1,132 +1,143 @@
dojo.provide("dojo.collections.Graph");
dojo.require("dojo.collections.Collections");
-dojo.collections.Graph = function(nodes){
+dojo.experimental("dojo.collections.Graph");
+
+dojo.collections.Graph=function(nodes){
function node(key, data, neighbors) {
- this.key = key;
- this.data = data;
- this.neighbors = neighbors || new adjacencyList();
- this.addDirected = function(){
- if (arguments[0].constructor == edgeToNeighbor){
+ this.key=key;
+ this.data=data;
+ this.neighbors=neighbors||new adjacencyList();
+ this.addDirected=function(){
+ if (arguments[0].constructor==edgeToNeighbor){
this.neighbors.add(arguments[0]);
- } else {
- var n = arguments[0];
- var cost = arguments[1] || 0;
+ }else{
+ var n=arguments[0];
+ var cost=arguments[1]||0;
this.neighbors.add(new edgeToNeighbor(n, cost));
}
}
}
function nodeList(){
- var d = new dojo.collections.Dictionary();
+ var d=new dojo.collections.Dictionary();
function nodelistiterator(){
- var o = [] ; // Create an indexing array
- var e = d.getIterator();
- while (e.moveNext()) o[o.length] = e.current;
+ var o=[] ; // Create an indexing array
+ var e=d.getIterator();
+ while(e.get()){
+ o[o.length]=e.element;
+ }
- var position = 0 ;
- this.current = null ;
- this.entry = null ;
- this.key = null ;
- this.value = null ;
- this.atEnd = false ;
- this.moveNext = function() {
- if (this.atEnd) return !this.atEnd ;
- this.entry = this.current = o[position] ;
- if (this.entry) {
- this.key = this.entry.key ;
- this.value = this.entry.data ;
+ var position=0;
+ this.element=o[position]||null;
+ this.atEnd=function(){
+ return (position>=o.length);
+ }
+ this.get=function(){
+ if(this.atEnd()){
+ return null; // object
}
- if (position == o.length) this.atEnd = true ;
- position++ ;
- return !this.atEnd ;
- } ;
- this.reset = function() {
- position = 0 ;
- this.atEnd = false ;
- } ;
+ this.element=o[position++];
+ return this.element; // object
+ };
+ this.map=function(/* function */fn, /* object? */scope){
+ var s=scope||dj_global;
+ if(Array.map){
+ return Array.map(o,fn,s); // array
+ }else{
+ var arr=[];
+ for(var i=0; i<o.length; i++){
+ arr.push(fn.call(s,o[i]));
+ }
+ return arr; // array
+ }
+ };
+ this.reset=function(){
+ position=0;
+ this.element=o[position];
+ };
}
- this.add = function(node){
+ this.add=function(node){
d.add(node.key, node);
};
- this.clear = function(){
+ this.clear=function(){
d.clear();
};
- this.containsKey = function(key){
+ this.containsKey=function(key){
return d.containsKey(key);
};
- this.getIterator = function(){
+ this.getIterator=function(){
return new nodelistiterator(this);
};
- this.item = function(key){
+ this.item=function(key){
return d.item(key);
};
- this.remove = function(node){
+ this.remove=function(node){
d.remove(node.key);
};
}
function edgeToNeighbor(node, cost){
- this.neighbor = node;
- this.cost = cost;
+ this.neighbor=node;
+ this.cost=cost;
}
function adjacencyList(){
- var d = [];
- this.add = function(o){
+ var d=[];
+ this.add=function(o){
d.push(o);
};
- this.item = function(i){
+ this.item=function(i){
return d[i];
};
- this.getIterator = function(){
+ this.getIterator=function(){
return new dojo.collections.Iterator([].concat(d));
};
}
- this.nodes = nodes || new nodeList();
- this.count = this.nodes.count;
- this.clear = function(){
+ this.nodes=nodes||new nodeList();
+ this.count=this.nodes.count;
+ this.clear=function(){
this.nodes.clear();
- this.count = 0;
+ this.count=0;
};
- this.addNode = function(){
- var n = arguments[0];
- if (arguments.length > 1) {
- n = new node(arguments[0], arguments[1]);
+ this.addNode=function(){
+ var n=arguments[0];
+ if(arguments.length > 1){
+ n=new node(arguments[0],arguments[1]);
}
- if (!this.nodes.containsKey(n.key)) {
+ if(!this.nodes.containsKey(n.key)){
this.nodes.add(n);
this.count++;
}
};
- this.addDirectedEdge = function(uKey, vKey, cost){
- var uNode, vNode;
- if (uKey.constructor != node) {
- uNode = this.nodes.item(uKey);
- vNode = this.nodes.item(vKey);
- } else {
- uNode = uKey;
- vNode = vKey;
+ this.addDirectedEdge=function(uKey, vKey, cost){
+ var uNode,vNode;
+ if(uKey.constructor!= node){
+ uNode=this.nodes.item(uKey);
+ vNode=this.nodes.item(vKey);
+ }else{
+ uNode=uKey;
+ vNode=vKey;
}
- var c = cost || 0;
- uNode.addDirected(vNode, c);
+ var c=cost||0;
+ uNode.addDirected(vNode,c);
};
- this.addUndirectedEdge = function(uKey, vKey, cost){
+ this.addUndirectedEdge=function(uKey, vKey, cost){
var uNode, vNode;
- if (uKey.constructor != node) {
- uNode = this.nodes.item(uKey);
- vNode = this.nodes.item(vKey);
- } else {
- uNode = uKey;
- vNode = vKey;
- }
- var c = cost || 0;
- uNode.addDirected(vNode, c);
- vNode.addDirected(uNode, c);
+ if(uKey.constructor!=node){
+ uNode=this.nodes.item(uKey);
+ vNode=this.nodes.item(vKey);
+ }else{
+ uNode=uKey;
+ vNode=vKey;
+ }
+ var c=cost||0;
+ uNode.addDirected(vNode,c);
+ vNode.addDirected(uNode,c);
};
- this.contains = function(n){
+ this.contains=function(n){
return this.nodes.containsKey(n.key);
};
- this.containsKey = function(k){
+ this.containsKey=function(k){
return this.nodes.containsKey(k);
};
}
Modified: trunk/src/collections/List.js
==============================================================================
--- trunk/src/collections/List.js (original)
+++ trunk/src/collections/List.js Mon Apr 17 15:09:07 2006
@@ -2,6 +2,6 @@
dojo.require("dojo.collections.Collections");
dojo.collections.List = function(dictionary){
- dojo.deprecated("dojo.collections.List", "Use dojo.collections.Dictionary instead.");
+ dojo.deprecated("dojo.collections.List", "Use dojo.collections.Dictionary instead.", "0.3");
return new dojo.collections.Dictionary(dictionary);
}
Modified: trunk/src/collections/Queue.js
==============================================================================
--- trunk/src/collections/Queue.js (original)
+++ trunk/src/collections/Queue.js Mon Apr 17 15:09:07 2006
@@ -1,41 +1,77 @@
dojo.provide("dojo.collections.Queue");
dojo.require("dojo.collections.Collections");
-dojo.collections.Queue = function(arr){
- var q = [];
- if (arr) q = q.concat(arr);
- this.count = q.length;
- this.clear = function(){
- q = [];
- this.count = q.length;
- };
- this.clone = function(){
- return new dojo.collections.Queue(q);
- };
- this.contains = function(o){
- for (var i = 0; i < q.length; i++){
- if (q[i] == o) return true;
+dojo.collections.Queue=function(/* array? */arr){
+ // summary
+ // return an object of type dojo.collections.Queue
+ var q=[];
+ if (arr){
+ q=q.concat(arr);
+ }
+ this.count=q.length;
+ this.clear=function(){
+ // summary
+ // clears the internal collection
+ q=[];
+ this.count=q.length;
+ };
+ this.clone=function(){
+ // summary
+ // creates a new Queue based on this one
+ return new dojo.collections.Queue(q); // dojo.collections.Queue
+ };
+ this.contains=function(/* object */ o){
+ // summary
+ // Check to see if the passed object is an element in this queue
+ for(var i=0; i<q.length; i++){
+ if (q[i]==o){
+ return true; // bool
+ }
}
- return false;
+ return false; // bool
};
- this.copyTo = function(arr, i){
+ this.copyTo=function(/* array */ arr, /* int */ i){
+ // summary
+ // Copy the contents of this queue into the passed array at index i.
arr.splice(i,0,q);
};
- this.dequeue = function(){
- var r = q.shift();
- this.count = q.length;
- return r;
- };
- this.enqueue = function(o){
- this.count = q.push(o);
- };
- this.getIterator = function(){
- return new dojo.collections.Iterator(q);
+ this.dequeue=function(){
+ // summary
+ // shift the first element off the queue and return it
+ var r=q.shift();
+ this.count=q.length;
+ return r; // object
+ };
+ this.enqueue=function(/* object */ o){
+ // summary
+ // put the passed object at the end of the queue
+ this.count=q.push(o);
+ };
+ this.forEach=function(/* function */ fn, /* object? */ scope){
+ // summary
+ // functional iterator, following the mozilla spec.
+ var s=scope||dj_global;
+ if(Array.forEach){
+ Array.forEach(q, fn, s);
+ }else{
+ for(var i=0; i<items.length; i++){
+ fn.call(s, q[i], i, q);
+ }
+ }
};
- this.peek = function(){
+ this.getIterator=function(){
+ // summary
+ // get an Iterator based on this queue.
+ return new dojo.collections.Iterator(q); // dojo.collections.Iterator
+ };
+ this.peek=function(){
+ // summary
+ // get the next element in the queue without altering the queue.
return q[0];
};
- this.toArray = function(){
+ this.toArray=function(){
+ // summary
+ // return an array based on the internal array of the queue.
return [].concat(q);
};
};
Modified: trunk/src/collections/Set.js
==============================================================================
--- trunk/src/collections/Set.js (original)
+++ trunk/src/collections/Set.js Mon Apr 17 15:09:07 2006
@@ -10,12 +10,12 @@
if (!setA.toArray || !setB.toArray) dojo.raise("Set operations can only be performed on array-based collections.");
var result = new dojo.collections.ArrayList(setA.toArray());
var e = setB.getIterator();
- do{
- if (!result.contains(e.current)){
- result.add(e.current);
+ while(!e.atEnd()){
+ var item=e.get();
+ if(!result.contains(item)){
+ result.add(item);
}
- e.moveNext();
- } while (!e.atEnd);
+ }
return result;
};
this.intersection = function(setA, setB){
@@ -24,10 +24,12 @@
if (!setA.toArray || !setB.toArray) dojo.raise("Set operations can only be performed on array-based collections.");
var result = new dojo.collections.ArrayList();
var e = setB.getIterator();
- do{
- if (setA.contains(e.current)) result.add(e.current);
- e.moveNext();
- }while(!e.atEnd);
+ while(!e.atEnd()){
+ var item=e.get();
+ if(setA.contains(item)){
+ result.add(item);
+ }
+ }
return result;
};
// returns everything in setA that is not in setB.
@@ -37,10 +39,12 @@
if (!setA.toArray || !setB.toArray) dojo.raise("Set operations can only be performed on array-based collections.");
var result = new dojo.collections.ArrayList();
var e=setA.getIterator();
- do{
- if (!setB.contains(e.current)) result.add(e.current);
- e.moveNext();
- }while(!e.atEnd);
+ while(!e.atEnd()){
+ var item=e.get();
+ if(!setB.contains(item)){
+ result.add(item);
+ }
+ }
return result;
};
this.isSubSet = function(setA, setB) {
@@ -48,10 +52,11 @@
if (setB.constructor == Array) var setB = new dojo.collections.ArrayList(setB);
if (!setA.toArray || !setB.toArray) dojo.raise("Set operations can only be performed on array-based collections.");
var e = setA.getIterator();
- do{
- if (!setB.contains(e.current)) return false;
- e.moveNext();
- }while(!e.atEnd);
+ while(!e.atEnd()){
+ if(!setB.contains(e.get())){
+ return false;
+ }
+ }
return true;
};
this.isSuperSet = function(setA, setB){
@@ -59,10 +64,11 @@
if (setB.constructor == Array) var setB = new dojo.collections.ArrayList(setB);
if (!setA.toArray || !setB.toArray) dojo.raise("Set operations can only be performed on array-based collections.");
var e = setB.getIterator();
- do{
- if (!setA.contains(e.current)) return false;
- e.moveNext();
- }while(!e.atEnd);
+ while(!e.atEnd()){
+ if(!setA.contains(e.get())){
+ return false;
+ }
+ }
return true;
};
}();
Modified: trunk/src/collections/SkipList.js
==============================================================================
--- trunk/src/collections/SkipList.js (original)
+++ trunk/src/collections/SkipList.js Mon Apr 17 15:09:07 2006
@@ -1,6 +1,8 @@
dojo.provide("dojo.collections.SkipList");
dojo.require("dojo.collections.Collections");
+dojo.experimental("dojo.collections.SkipList");
+
dojo.collections.SkipList = function(){
function node(height, val){
this.value = val;
Modified: trunk/src/collections/SortedList.js
==============================================================================
--- trunk/src/collections/SortedList.js (original)
+++ trunk/src/collections/SortedList.js Mon Apr 17 15:09:07 2006
@@ -1,18 +1,21 @@
dojo.provide("dojo.collections.SortedList");
dojo.require("dojo.collections.Collections");
-dojo.collections.SortedList = function(dictionary){
- var _this = this;
- var items = {};
- var q = [];
- var sorter = function(a,b){
+dojo.collections.SortedList=function(/* object? */ dictionary){
+ // summary
+ // creates a collection that acts like a dictionary but is also internally sorted.
+ // Note that the act of adding any elements forces an internal resort, making this object potentially slow.
+ var _this=this;
+ var items={};
+ var q=[];
+ var sorter=function(a,b){
if (a.key > b.key) return 1;
if (a.key < b.key) return -1;
return 0;
};
- var build = function(){
- q = [];
- var e = _this.getIterator();
+ var build=function(){
+ q=[];
+ var e=_this.getIterator();
while (!e.atEnd) {
q.push(e.entry);
e.moveNext();
@@ -20,126 +23,175 @@
q.sort(sorter);
};
- this.count = q.length;
- this.add = function(k,v){
+ this.count=q.length;
+ this.add=function(/* string */ k,/* object */v){
+ // summary
+ // add the passed value to the dictionary at location k
if (!items[k]) {
- items[k] = new dojo.collections.DictionaryEntry(k,v);
- this.count = q.push(items[k]);
+ items[k]=new dojo.collections.DictionaryEntry(k,v);
+ this.count=q.push(items[k]);
q.sort(sorter);
}
};
- this.clear = function(){
- items = {};
- q = [];
- this.count = q.length;
- };
- this.clone = function(){
- return new dojo.collections.SortedList(this);
- };
- this.contains = this.containsKey = function(k){
- return (items[k] != null);
- };
- this.containsValue = function(o){
- var e = this.getIterator();
- while (!e.atEnd){
- if (e.value == o) return true;
- e.moveNext();
+ this.clear=function(){
+ // summary
+ // clear the internal collections
+ items={};
+ q=[];
+ this.count=q.length;
+ };
+ this.clone=function(){
+ // summary
+ // create a clone of this sorted list
+ return new dojo.collections.SortedList(this); // dojo.collections.SortedList
+ };
+ this.contains=this.containsKey=function(/* string */ k){
+ // summary
+ // Check to see if the list has a location k
+ return (items[k]!=null); // bool
+ };
+ this.containsValue=function(/* object */ o){
+ // summary
+ // Check to see if this list contains the passed object
+ var e=this.getIterator();
+ while (!e.atEnd()){
+ var item=e.get();
+ if(item.value==o){
+ return true; // bool
+ }
}
- return false;
+ return false; // bool
};
- this.copyTo = function(arr, i){
- var e = this.getIterator();
- var idx = i;
- while (!e.atEnd){
- arr.splice(idx, 0, e.entry);
+ this.copyTo=function(/* array */ arr, /* int */ i){
+ // summary
+ // copy the contents of the list into array arr at index i
+ var e=this.getIterator();
+ var idx=i;
+ while(!e.atEnd()){
+ arr.splice(idx,0,e.get());
idx++;
- e.moveNext();
}
};
- this.entry=function(k){
- return items[k];
- };
- this.getByIndex = function(i){
- return q[i].valueOf();
- };
- this.getIterator = function(){
- return new dojo.collections.DictionaryIterator(items);
- };
- this.getKey = function(i){
- return q[i].key;
- };
- this.getKeyList = function(){
- var arr = [];
- var e = this.getIterator();
- while (!e.atEnd){
- arr.push(e.key);
- e.moveNext();
+ this.entry=function(/* string */ k){
+ // summary
+ // return the object at location k
+ return items[k]; // dojo.collections.DictionaryEntry
+ };
+ this.forEach=function(/* function */ fn, /* object? */ scope){
+ // summary
+ // functional iterator, following the mozilla spec.
+ var s=scope||dj_global;
+ if(Array.forEach){
+ Array.forEach(q, fn, s);
+ }else{
+ for(var i=0; i<q.length; i++){
+ fn.call(s, q[i], i, q);
+ }
}
- return arr;
};
- this.getValueList = function(){
- var arr = [];
- var e = this.getIterator();
- while (!e.atEnd){
- arr.push(e.value);
- e.moveNext();
- }
- return arr;
+ this.getByIndex=function(/* int */ i){
+ // summary
+ // return the item at index i
+ return q[i].valueOf(); // object
+ };
+ this.getIterator=function(){
+ // summary
+ // get an iterator for this object
+ return new dojo.collections.DictionaryIterator(items); // dojo.collections.DictionaryIterator
+ };
+ this.getKey=function(/* int */ i){
+ // summary
+ // return the key of the item at index i
+ return q[i].key;
};
- this.indexOfKey = function(k){
- for (var i = 0; i < q.length; i++){
- if (q[i].key == k) {
- return i;
+ this.getKeyList=function(){
+ // summary
+ // return an array of the keys set in this list
+ var arr=[];
+ var e=this.getIterator();
+ while (!e.atEnd()){
+ arr.push(e.get().key);
+ }
+ return arr; // array
+ };
+ this.getValueList=function(){
+ // summary
+ // return an array of values in this list
+ var arr=[];
+ var e=this.getIterator();
+ while (!e.atEnd()){
+ arr.push(e.get().value);
+ }
+ return arr; // array
+ };
+ this.indexOfKey=function(/* string */ k){
+ // summary
+ // return the index of the passed key.
+ for (var i=0; i<q.length; i++){
+ if (q[i].key==k){
+ return i; // int
}
}
- return -1;
+ return -1; // int
};
- this.indexOfValue = function(o){
- for (var i = 0; i < q.length; i++){
- if (q[i].value == o) {
- return i;
+ this.indexOfValue=function(/* object */ o){
+ // summary
+ // return the first index of object o
+ for (var i=0; i<q.length; i++){
+ if (q[i].value==o){
+ return i; // int
}
}
- return -1;
- };
- this.item = function(k){
- return items[k].valueOf();
+ return -1; // int
};
-
- this.remove = function(k){
+ this.item=function(/* string */ k){
+ // summary
+ // return the value of the object at location k.
+ if(k in items){
+ return items[k].valueOf(); // object
+ }
+ return undefined; // object
+ };
+ this.remove=function(/* string */k){
+ // summary
+ // remove the item at location k and rebuild the internal collections.
delete items[k];
build();
- this.count = q.length;
+ this.count=q.length;
};
-
- this.removeAt = function(i){
+ this.removeAt=function(/* int */ i){
+ // summary
+ // remove the item at index i, and rebuild the internal collections.
delete items[q[i].key];
build();
- this.count = q.length;
+ this.count=q.length;
};
-
- this.replace = function(k,v){
- if (!items[k]) {
+ this.replace=function(/* string */ k, /* object */ v){
+ // summary
+ // Replace an existing item if it's there, and add a new one if not.
+ if (!items[k]){
+ // we're adding a new object, return false
this.add(k,v);
- return false; // returning false because we added rather than replaced
- } else {
- items[k] = new dojo.collections.DictionaryEntry(k,v);
+ return false; // bool
+ }else{
+ // we're replacing an object, return true
+ items[k]=new dojo.collections.DictionaryEntry(k,v);
q.sort(sorter);
- return true; // returning true because we replaced a value
+ return true; // bool
}
};
-
- this.setByIndex = function(i,o){
- items[q[i].key].value = o;
+ this.setByIndex=function(/* int */ i, /* object */ o){
+ // summary
+ // set an item by index
+ items[q[i].key].value=o;
build();
- this.count = q.length;
+ this.count=q.length;
};
-
if (dictionary){
- var e = dictionary.getIterator();
- while (!e.atEnd) {
- q[q.length] = items[e.key] = new dojo.collections.DictionaryEntry(e.key, e.value);
- e.moveNext();
+ var e=dictionary.getIterator();
+ while (!e.atEnd()){
+ var item=e.get();
+ q[q.length]=items[item.key]=new dojo.collections.DictionaryEntry(item.key,item.value);
}
q.sort(sorter);
}
Modified: trunk/src/collections/Stack.js
==============================================================================
--- trunk/src/collections/Stack.js (original)
+++ trunk/src/collections/Stack.js Mon Apr 17 15:09:07 2006
@@ -1,41 +1,75 @@
dojo.provide("dojo.collections.Stack");
dojo.require("dojo.collections.Collections");
-dojo.collections.Stack = function(arr){
- var q = [];
- if (arr) q = q.concat(arr);
- this.count = q.length;
- this.clear = function(){
- q = [];
- this.count = q.length;
- };
- this.clone = function(){
+dojo.collections.Stack=function(/* array? */arr){
+ // summary
+ // returns an object of type dojo.collections.Stack
+ var q=[];
+ if (arr) q=q.concat(arr);
+ this.count=q.length;
+ this.clear=function(){
+ // summary
+ // Clear the internal array and reset the count
+ q=[];
+ this.count=q.length;
+ };
+ this.clone=function(){
+ // summary
+ // Create and return a clone of this Stack
return new dojo.collections.Stack(q);
};
- this.contains = function(o){
- for (var i = 0; i < q.length; i++){
- if (q[i] == o) return true;
+ this.contains=function(/* object */o){
+ // summary
+ // check to see if the stack contains object o
+ for (var i=0; i<q.length; i++){
+ if (q[i] == o){
+ return true; // bool
+ }
}
- return false;
+ return false; // bool
};
- this.copyTo = function(arr, i){
+ this.copyTo=function(/* array */ arr, /* int */ i){
+ // summary
+ // copy the stack into array arr at index i
arr.splice(i,0,q);
};
- this.getIterator = function(){
- return new dojo.collections.Iterator(q);
- };
- this.peek = function(){
- return q[(q.length - 1)];
- };
- this.pop = function(){
- var r = q.pop();
- this.count = q.length;
- return r;
- };
- this.push = function(o){
- this.count = q.push(o);
+ this.forEach=function(/* function */ fn, /* object? */ scope){
+ // summary
+ // functional iterator, following the mozilla spec.
+ var s=scope||dj_global;
+ if(Array.forEach){
+ Array.forEach(q, fn, s);
+ }else{
+ for(var i=0; i<items.length; i++){
+ fn.call(s, q[i], i, q);
+ }
+ }
};
- this.toArray = function(){
- return [].concat(q);
+ this.getIterator=function(){
+ // summary
+ // get an iterator for this collection
+ return new dojo.collections.Iterator(q); // dojo.collections.Iterator
+ };
+ this.peek=function(){
+ // summary
+ // Return the next item without altering the stack itself.
+ return q[(q.length-1)]; // object
+ };
+ this.pop=function(){
+ // summary
+ // pop and return the next item on the stack
+ var r=q.pop();
+ this.count=q.length;
+ return r; // object
+ };
+ this.push=function(/* object */ o){
+ // summary
+ // Push object o onto the stack
+ this.count=q.push(o);
+ };
+ this.toArray=function(){
+ // summary
+ // create and return an array based on the internal collection
+ return [].concat(q); // array
};
}
Modified: trunk/src/crypto/Rijndael.js
==============================================================================
--- trunk/src/crypto/Rijndael.js (original)
+++ trunk/src/crypto/Rijndael.js Mon Apr 17 15:09:07 2006
@@ -1,11 +1,11 @@
dojo.provide("dojo.crypto.Rijndael");
dojo.require("dojo.crypto");
+dojo.experimental("dojo.crypto.Rijndael");
+
dojo.crypto.Rijndael = new function(){
this.encrypt=function(plaintext, key){
};
this.decrypt=function(ciphertext, key){
};
}();
-
-dojo.crypto.AES = dojo.crypto.Rijndael; // alias
Modified: trunk/src/crypto/SHA1.js
==============================================================================
--- trunk/src/crypto/SHA1.js (original)
+++ trunk/src/crypto/SHA1.js Mon Apr 17 15:09:07 2006
@@ -1,6 +1,8 @@
dojo.require("dojo.crypto");
dojo.provide("dojo.crypto.SHA1");
+dojo.experimental("dojo.crypto.SHA1");
+
dojo.crypto.SHA1 = new function(){
var chrsz=8;
var mask=(1<<chrsz)-1;
Modified: trunk/src/crypto/SHA256.js
==============================================================================
--- trunk/src/crypto/SHA256.js (original)
+++ trunk/src/crypto/SHA256.js Mon Apr 17 15:09:07 2006
@@ -1,6 +1,8 @@
dojo.provide("dojo.crypto.SHA256");
dojo.require("dojo.crypto");
+dojo.experimental("dojo.crypto.SHA256");
+
dojo.crypto.SHA256 = new function(){
this.compute=function(s){
};
Modified: trunk/src/svg.js
==============================================================================
--- trunk/src/svg.js (original)
+++ trunk/src/svg.js Mon Apr 17 15:09:07 2006
@@ -4,73 +4,91 @@
dojo.lang.mixin(dojo.svg, dojo.dom);
-/**
- * The Graphics object. Hopefully gives the user a way into
- * XPlatform rendering functions supported correctly and incorrectly.
-**/
-dojo.svg.graphics = dojo.svg.g = new function(d){
- this.suspend = function(){
+dojo.svg.graphics=dojo.svg.g=new function(/* DomDocument */ d){
+ // summary
+ // Singleton to encapsulate SVG rendering functions.
+ this.suspend=function(){
+ // summary
+ // Suspend the rendering engine
try { d.documentElement.suspendRedraw(0); } catch(e){ }
};
- this.resume = function(){
+ this.resume=function(){
+ // summary
+ // Resume the rendering engine
try { d.documentElement.unsuspendRedraw(0); } catch(e){ }
};
- this.force = function(){
+ this.force=function(){
+ // summary
+ // Force the render engine to redraw
try { d.documentElement.forceRedraw(); } catch(e){ }
};
}(document);
-/**
- * The Animations control object. Hopefully gives the user a way into
- * XPlatform animation functions supported correctly and incorrectly.
-**/
-dojo.svg.animations = dojo.svg.anim = new function(d){
- this.arePaused = function(){
+dojo.svg.animations=dojo.svg.anim=new function(/* DOMDocument */ d){
+ // summary
+ // Singleton to encapsulate SVG animation functionality.
+ this.arePaused=function(){
+ // summary
+ // check to see if all animations are paused
try {
- return d.documentElement.animationsPaused();
+ return d.documentElement.animationsPaused(); // bool
} catch(e){
- return false;
+ return false; // bool
}
} ;
- this.pause = function(){
+ this.pause=function(){
+ // summary
+ // pause all animations
try { d.documentElement.pauseAnimations(); } catch(e){ }
};
- this.resume = function(){
+ this.resume=function(){
+ // summary
+ // resume all animations
try { d.documentElement.unpauseAnimations(); } catch(e){ }
};
}(document);
-/**
- * signatures from dojo.style.
- */
-dojo.svg.toCamelCase = function(selector){
- var arr = selector.split('-'), cc = arr[0];
- for(var i = 1; i < arr.length; i++) {
+// fixme: these functions should be mixed in from dojo.style, but dojo.style is HTML-centric and needs to change.
+dojo.svg.toCamelCase=function(/* string */ selector){
+ // summary
+ // converts a CSS-style selector to a camelCased one
+ var arr=selector.split('-'), cc=arr[0];
+ for(var i=1; i < arr.length; i++) {
cc += arr[i].charAt(0).toUpperCase() + arr[i].substring(1);
}
- return cc;
-};
-dojo.svg.toSelectorCase = function (selector) {
- return selector.replace(/([A-Z])/g, "-$1" ).toLowerCase() ;
+ return cc; // string
};
-dojo.svg.getStyle = function(node, cssSelector){
- return document.defaultView.getComputedStyle(node, cssSelector);
-};
-dojo.svg.getNumericStyle = function(node, cssSelector){
+dojo.svg.toSelectorCase=function(/* string */ selector) {
+ // summary
+ // converts a camelCased selector to a CSS style one
+ return selector.replace(/([A-Z])/g, "-$1" ).toLowerCase(); // string
+};
+dojo.svg.getStyle=function(/* SVGElement */ node, /* string */ cssSelector){
+ // summary
+ // get the computed style of selector for node.
+ return document.defaultView.getComputedStyle(node, cssSelector); // object
+};
+dojo.svg.getNumericStyle=function(/* SVGElement */ node, /* string */ cssSelector){
+ // summary
+ // return the numeric version of the computed style of selector on node.
return parseFloat(dojo.svg.getStyle(node, cssSelector));
};
-/**
- * alpha channel operations
- */
-dojo.svg.getOpacity = function(node){
- return Math.min(1.0, dojo.svg.getNumericStyle(node, "fill-opacity"));
-};
-dojo.svg.setOpacity = function(node, opacity){
+// fixme: there are different ways of doing the following, need to take into account
+dojo.svg.getOpacity=function(/* SVGElement */node){
+ // summary
+ // Return the opacity of the passed element
+ return Math.min(1.0, dojo.svg.getNumericStyle(node, "fill-opacity")); // float
+};
+dojo.svg.setOpacity=function(/* SVGElement */ node, /* float */ opacity){
+ // summary
+ // set the opacity of node using attributes.
node.setAttributeNS(this.xmlns.svg, "fill-opacity", opacity);
node.setAttributeNS(this.xmlns.svg, "stroke-opacity", opacity);
};
-dojo.svg.clearOpacity = function(node){
+dojo.svg.clearOpacity=function(/* SVGElement */ node){
+ // summary
+ // Set any attributes setting opacity to opaque (1.0)
node.setAttributeNS(this.xmlns.svg, "fill-opacity", "1.0");
node.setAttributeNS(this.xmlns.svg, "stroke-opacity", "1.0");
};
@@ -78,105 +96,107 @@
/**
* Coordinates and dimensions.
*/
-dojo.svg.getCoords = function(node){
+
+// TODO ////////////////////////////////////////////////////////// TODO
+dojo.svg.getCoords=function(/* SVGElement */ node){
if (node.getBBox) {
- var box = node.getBBox();
+ var box=node.getBBox();
return { x: box.x, y: box.y };
}
return null;
};
-dojo.svg.setCoords = function(node, coords){
- var p = dojo.svg.getCoords();
+dojo.svg.setCoords=function(node, coords){
+ var p=dojo.svg.getCoords();
if (!p) return;
- var dx = p.x - coords.x;
- var dy = p.y - coords.y;
+ var dx=p.x - coords.x;
+ var dy=p.y - coords.y;
dojo.svg.translate(node, dx, dy);
};
-dojo.svg.getDimensions = function(node){
+dojo.svg.getDimensions=function(node){
if (node.getBBox){
- var box = node.getBBox();
+ var box=node.getBBox();
return { width: box.width, height : box.height };
}
return null;
};
-dojo.svg.setDimensions = function(node, dim){
+dojo.svg.setDimensions=function(node, dim){
// will only support shape-based and container elements; path-based elements are ignored.
if (node.width){
- node.width.baseVal.value = dim.width;
- node.height.baseVal.vaule = dim.height;
+ node.width.baseVal.value=dim.width;
+ node.height.baseVal.vaule=dim.height;
}
else if (node.r){
- node.r.baseVal.value = Math.min(dim.width, dim.height)/2;
+ node.r.baseVal.value=Math.min(dim.width, dim.height)/2;
}
else if (node.rx){
- node.rx.baseVal.value = dim.width/2;
- node.ry.baseVal.value = dim.height/2;
+ node.rx.baseVal.value=dim.width/2;
+ node.ry.baseVal.value=dim.height/2;
}
};
/**
* Transformations.
*/
-dojo.svg.translate = function(node, dx, dy){
+dojo.svg.translate=function(node, dx, dy){
if (node.transform && node.ownerSVGElement && node.ownerSVGElement.createSVGTransform){
- var t = node.ownerSVGElement.createSVGTransform();
+ var t=node.ownerSVGElement.createSVGTransform();
t.setTranslate(dx, dy);
node.transform.baseVal.appendItem(t);
}
};
-dojo.svg.scale = function(node, scaleX, scaleY){
- if (!scaleY) var scaleY = scaleX;
+dojo.svg.scale=function(node, scaleX, scaleY){
+ if (!scaleY) var scaleY=scaleX;
if (node.transform && node.ownerSVGElement && node.ownerSVGElement.createSVGTransform){
- var t = node.ownerSVGElement.createSVGTransform();
+ var t=node.ownerSVGElement.createSVGTransform();
t.setScale(scaleX, scaleY);
node.transform.baseVal.appendItem(t);
}
};
-dojo.svg.rotate = function(node, ang, cx, cy){
+dojo.svg.rotate=function(node, ang, cx, cy){
if (node.transform && node.ownerSVGElement && node.ownerSVGElement.createSVGTransform){
- var t = node.ownerSVGElement.createSVGTransform();
+ var t=node.ownerSVGElement.createSVGTransform();
if (!cx) t.setMatrix(t.matrix.rotate(ang));
else t.setRotate(ang, cx, cy);
node.transform.baseVal.appendItem(t);
}
};
-dojo.svg.skew = function(node, ang, axis){
- var dir = axis || "x";
+dojo.svg.skew=function(node, ang, axis){
+ var dir=axis || "x";
if (node.transform && node.ownerSVGElement && node.ownerSVGElement.createSVGTransform){
- var t = node.ownerSVGElement.createSVGTransform();
+ var t=node.ownerSVGElement.createSVGTransform();
if (dir != "x") t.setSkewY(ang);
else t.setSkewX(ang);
node.transform.baseVal.appendItem(t);
}
};
-dojo.svg.flip = function(node, axis){
- var dir = axis || "x";
+dojo.svg.flip=function(node, axis){
+ var dir=axis || "x";
if (node.transform && node.ownerSVGElement && node.ownerSVGElement.createSVGTransform){
- var t = node.ownerSVGElement.createSVGTransform();
+ var t=node.ownerSVGElement.createSVGTransform();
t.setMatrix((dir != "x") ? t.matrix.flipY() : t.matrix.flipX());
node.transform.baseVal.appendItem(t);
}
};
-dojo.svg.invert = function(node){
+dojo.svg.invert=function(node){
if (node.transform && node.ownerSVGElement && node.ownerSVGElement.createSVGTransform){
- var t = node.ownerSVGElement.createSVGTransform();
+ var t=node.ownerSVGElement.createSVGTransform();
t.setMatrix(t.matrix.inverse());
node.transform.baseVal.appendItem(t);
}
};
-dojo.svg.applyMatrix = function(node, a, b, c, d, e, f){
+dojo.svg.applyMatrix=function(node, a, b, c, d, e, f){
if (node.transform && node.ownerSVGElement && node.ownerSVGElement.createSVGTransform){
var m;
if (b){
- var m = node.ownerSVGElement.createSVGMatrix();
- m.a = a;
- m.b = b;
- m.c = c;
- m.d = d;
- m.e = e;
- m.f = f;
- } else m = a;
- var t = node.ownerSVGElement.createSVGTransform();
+ var m=node.ownerSVGElement.createSVGMatrix();
+ m.a=a;
+ m.b=b;
+ m.c=c;
+ m.d=d;
+ m.e=e;
+ m.f=f;
+ } else m=a;
+ var t=node.ownerSVGElement.createSVGTransform();
t.setMatrix(m);
node.transform.baseVal.appendItem(t);
}
@@ -185,83 +205,65 @@
/**
* Grouping and z-index operations.
*/
-dojo.svg.group = function(nodes){
+dojo.svg.group=function(nodes){
// expect an array of nodes, attaches the group to the parent of the first node.
- var p = nodes.item(0).parentNode;
- var g = document.createElementNS(this.xmlns.svg, "g");
- for (var i = 0; i < nodes.length; i++) g.appendChild(nodes.item(i));
+ var p=nodes.item(0).parentNode;
+ var g=document.createElementNS(this.xmlns.svg, "g");
+ for (var i=0; i < nodes.length; i++) g.appendChild(nodes.item(i));
p.appendChild(g);
return g;
};
-dojo.svg.ungroup = function(g){
+dojo.svg.ungroup=function(g){
// puts the children of the group on the same level as group was.
- var p = g.parentNode;
+ var p=g.parentNode;
while (g.childNodes.length > 0) p.appendChild(g.childNodes.item(0));
p.removeChild(g);
};
// if the node is part of a group, return the group, else return null.
-dojo.svg.getGroup = function(node){
+dojo.svg.getGroup=function(node){
// if the node is part of a group, return the group, else return null.
- var a = this.getAncestors(node);
- for (var i = 0; i < a.length; i++){
+ var a=this.getAncestors(node);
+ for (var i=0; i < a.length; i++){
if (a[i].nodeType == this.ELEMENT_NODE && a[i].nodeName.toLowerCase() == "g")
return a[i];
}
return null;
};
-dojo.svg.bringToFront = function(node){
- var n = this.getGroup(node) || node;
+dojo.svg.bringToFront=function(node){
+ var n=this.getGroup(node) || node;
n.ownerSVGElement.appendChild(n);
};
-dojo.svg.sendToBack = function(node){
- var n = this.getGroup(node) || node;
+dojo.svg.sendToBack=function(node){
+ var n=this.getGroup(node) || node;
n.ownerSVGElement.insertBefore(n, n.ownerSVGElement.firstChild);
};
+
// TODO: possibly push node up a level in the DOM if it's at the beginning or end of the childNodes list.
-dojo.svg.bringForward = function(node){
- var n = this.getGroup(node) || node;
+dojo.svg.bringForward=function(node){
+ var n=this.getGroup(node) || node;
if (this.getLastChildElement(n.parentNode) != n){
this.insertAfter(n, this.getNextSiblingElement(n), true);
}
};
-dojo.svg.sendBackward = function(node){
- var n = this.getGroup(node) || node;
+dojo.svg.sendBackward=function(node){
+ var n=this.getGroup(node) || node;
if (this.getFirstChildElement(n.parentNode) != n){
this.insertBefore(n, this.getPreviousSiblingElement(n), true);
}
};
-// modded to account for FF 1.5 mixed environment, will try ASVG first, then w3 standard.
-dojo.dom.createNodesFromText = function (txt, wrap){
- var docFrag;
- if (window.parseXML) docFrag = parseXML(txt, window.document);
- else if (window.DOMParser) docFrag = (new DOMParser()).parseFromString(txt, "text/xml");
- else dojo.raise("dojo.dom.createNodesFromText: environment does not support XML parsing");
- docFrag.normalize();
+// END TODO ////////////////////////////////////////////////////// TODO
+
+dojo.svg.createNodesFromText=function(/* string */ txt, /* bool? */ wrap){
+ // summary
+ // Create a list of nodes from text
+ var docFrag=(new DOMParser()).parseFromString(txt, "text/xml").normalize();
if(wrap){
- var ret = [docFrag.firstChild.cloneNode(true)];
- return ret;
+ return [docFrag.firstChild.cloneNode(true)]; // array
}
- var nodes = [];
+ var nodes=[];
for(var x=0; x<docFrag.childNodes.length; x++){
nodes.push(docFrag.childNodes.item(x).cloneNode(true));
}
- // tn.style.display = "none";
- return nodes;
-}
-
-// FIXME: this should be removed after 0.2 release
-if(!dojo.evalObjPath("dojo.dom.createNodesFromText")) {
- dojo.dom.createNodesFromText = function() {
- dojo.deprecated("dojo.dom.createNodesFromText", "use dojo.svg.createNodesFromText instead");
- dojo.svg.createNodesFromText.apply(dojo.html, arguments);
- }
-}
-
-// IE INLINE FIX
-/*
-if (dojo.render.html.ie && dojo.render.svg.adobe){
- document.write("<object id=\"AdobeSVG\" classid=\"clsid:78156a80-c6a1-4bbf-8e6a-3cd390eeb4e2\"></object>");
- document.write("<?import namespace=\"svg\" urn=\"http://www.w3.org/2000/svg\" implementation=\"#AdobeSVG\"?>");
+ return nodes; // array
}
-*/
// vim:ts=4:noet:tw=0:
Modified: trunk/tests/collections/test_Dictionary.html
==============================================================================
--- trunk/tests/collections/test_Dictionary.html (original)
+++ trunk/tests/collections/test_Dictionary.html Mon Apr 17 15:09:07 2006
@@ -17,46 +17,118 @@
d.add("baz","fab");
d.add("buck","shot");
d.add("apple",{test:"orange",toString:function(){ return this.test; }});
-
+
var s = [];
var e = d.getIterator();
// testing while form.
- s.push("...testing while form...");
- while(!e.atEnd){
- s.push(e.key + " == " + e.value);
- e.moveNext();
+ s.push("...testing while(!atEnd) form...");
+ while(!e.atEnd()){
+ var item=e.get();
+ s.push(item.key + " == " + item.value);
}
e.reset();
+ s.push("...testing while(var item=e.get()) form...");
+ var item;
+ while(item=e.get()){
+ s.push(item.key + " == " + item.value);
+ }
+ e.reset();
+
// testing do...while form.
s.push(" ");
s.push("...testing do...while form...");
- if (!e.atEnd){
- do {
- s.push(e.key + " == " + e.value);
- } while (e.moveNext());
- }
+ do {
+ var item=e.get();
+ s.push(item.key + " == " + item.value);
+ } while (!e.atEnd());
e.reset();
// testing for form
s.push(" ");
s.push("...testing for form...");
- for (; !e.atEnd; e.moveNext()){
- s.push(e.key + " == " + e.value);
+ for (var item=e.element; item=e.get();){
+ s.push(item.key + " == " + item.value);
}
s.push(" ");
s.push("...testing with no elements...");
var d = new dojo.collections.Dictionary();
var e = d.getIterator();
- if (!e.atEnd){
- do {
- s.push(e.key + " == " + e.value);
- } while (e.moveNext());
+ s.push("...testing while form...");
+ while(!e.atEnd()){
+ var item=e.get();
+ s.push(item.key + " == " + item.value);
+ }
+ e.reset();
+
+ s.push("...testing while(var item=e.get()) form...");
+ var item;
+ while(item=e.get()){
+ s.push(item.key + " == " + item.value);
+ }
+ e.reset();
+
+ // testing do...while form.
+ s.push(" ");
+ s.push("...testing do...while form...");
+ do {
+ var item=e.get();
+ try{
+ s.push(item.key + " == " + item.value);
+ } catch(e){
+ s.push("do...while: " +e.message);
+ }
+ } while (!e.atEnd());
+ e.reset();
+
+ // testing for form
+ s.push(" ");
+ s.push("...testing for form...");
+ for (;!e.atEnd();){
+ var item=e.get();
+ s.push(item.key + " == " + item.value);
}
- document.getElementsByTagName("body")[0].innerHTML = s.join("<br/>");
+ s.push(" ");
+ s.push("...testing with one element...");
+ var d = new dojo.collections.Dictionary();
+ d.add("apple",{test:"orange",toString:function(){ return this.test; }});
+ var e = d.getIterator();
+ s.push("...testing while form...");
+ while(!e.atEnd()){
+ var item=e.get();
+ s.push(item.key + " == " + item.value);
+ }
+ e.reset();
+
+ s.push("...testing while(var item=e.get()) form...");
+ var item;
+ while(item=e.get()){
+ s.push(item.key + " == " + item.value);
+ }
+ e.reset();
+
+ // testing do...while form.
+ s.push(" ");
+ s.push("...testing do...while form...");
+ do {
+ var item=e.get();
+ s.push(item.key + " == " + item.value);
+ } while (!e.atEnd());
+ e.reset();
+
+ // testing for form
+ s.push(" ");
+ s.push("...testing for form...");
+ for (;!e.atEnd();){
+ var item=e.get();
+ s.push(item.key + " == " + item.value);
+ }
+
+ document.getElementsByTagName("body")[0].innerHTML = s.join("<br/>");
+
// run the unit tests now.
test_Dictionary_ctor();
test_Dictionary_add();
More information about the Dojo-checkins
mailing list