Fix keys conflict in CPDictionary

[#77 state:resolved]
This commit is contained in:
Ross Boucher committed 2008-09-30 17:29:56 -07:00
1 parent bbc6ef7602
commit 01177a7e02
3 files changed
+31 -31

No files matched your search

BIN
View File
Binary file not shown.
+10 -10
View File
@@ -133,7 +133,7 @@ import "CPException.j"
var key = "",
dictionary = [[CPDictionary alloc] init];
for (key in aDictionary.buckets)
for (key in aDictionary._buckets)
[dictionary setObject:[aDictionary objectForKey:key] forKey:key];
return dictionary;
@@ -177,7 +177,7 @@ import "CPException.j"
*/
- (CPArray)allKeys
{
return keys;
return _keys;
}
/*
@@ -185,11 +185,11 @@ import "CPException.j"
*/
- (CPArray)allValues
{
var index = keys.length,
var index = _keys.length,
values = [];
while (index--)
values.push(dictionary_getValue(self, [keys[index]]));
values.push(dictionary_getValue(self, [_keys[index]]));
return values;
}
@@ -199,7 +199,7 @@ import "CPException.j"
*/
- (CPEnumerator)keyEnumerator
{
return [keys objectEnumerator];
return [_keys objectEnumerator];
}
/*
@@ -271,7 +271,7 @@ import "CPException.j"
- (id)objectForKey:(CPString)aKey
{
// We should really do this with inlining or something of that nature.
return buckets[aKey];
return _buckets[aKey];
//return dictionary_getValue(self, aKey);
}
/*
@@ -311,9 +311,9 @@ import "CPException.j"
*/
- (void)removeAllObjects
{
keys = [];
_keys = [];
count = 0;
buckets = {};
_buckets = {};
}
/*
@@ -380,10 +380,10 @@ import "CPException.j"
{
var description = @"CPDictionary {\n";
var i = keys.length;
var i = _keys.length;
while (i--)
description += keys[i] +":"+[buckets[keys[i]] description]+"\n";
description += _keys[i] +":"+[_buckets[_keys[i]] description]+"\n";
description += "}";
+21 -21
View File
@@ -22,18 +22,18 @@
function objj_dictionary()
{
this.keys = [];
this.count = 0;
this.buckets = {};
this.__address = _objj_generateObjectHash();
this._keys = [];
this.count = 0;
this._buckets = {};
this.__address = _objj_generateObjectHash();
}
function dictionary_containsKey(aDictionary, aKey)
{
return aDictionary.buckets[aKey] != NULL;
return aDictionary._buckets[aKey] != NULL;
}
#define dictionary_containsKey(aDictionary, aKey) ((aDictionary).buckets[aKey] != NULL)
#define dictionary_containsKey(aDictionary, aKey) ((aDictionary)._buckets[aKey] != NULL)
function dictionary_getCount(aDictionary)
{
@@ -44,47 +44,47 @@ function dictionary_getCount(aDictionary)
function dictionary_getValue(aDictionary, aKey)
{
return aDictionary.buckets[aKey];
return aDictionary._buckets[aKey];
}
#define dictionary_getValue(aDictionary, aKey) ((aDictionary).buckets[aKey])
#define dictionary_getValue(aDictionary, aKey) ((aDictionary)._buckets[aKey])
function dictionary_setValue(aDictionary, aKey, aValue)
{
if (aDictionary.buckets[aKey] == NULL)
if (aDictionary._buckets[aKey] == NULL)
{
aDictionary.keys.push(aKey);
aDictionary._keys.push(aKey);
++aDictionary.count;
}
if ((aDictionary.buckets[aKey] = aValue) == NULL)
if ((aDictionary._buckets[aKey] = aValue) == NULL)
--aDictionary.count;
}
#define dictionary_setValue(aDictionary, aKey, aValue)\
{\
if ((aDictionary).buckets[aKey] == NULL)\
if ((aDictionary)._buckets[aKey] == NULL)\
{\
(aDictionary).keys.push(aKey);\
(aDictionary)._keys.push(aKey);\
++(aDictionary).count;\
}\
\
if (((aDictionary).buckets[aKey] = aValue) == NULL) \
if (((aDictionary)._buckets[aKey] = aValue) == NULL) \
--(aDictionary).count;\
}
function dictionary_removeValue(aDictionary, aKey)
{
if (aDictionary.buckets[aKey] == NULL)
if (aDictionary._buckets[aKey] == NULL)
return;
--aDictionary.count;
if (aDictionary.keys.indexOf)
aDictionary.keys.splice(aDictionary.keys.indexOf(aKey), 1);
if (aDictionary._keys.indexOf)
aDictionary._keys.splice(aDictionary._keys.indexOf(aKey), 1);
else
{
var keys = aDictionary.keys,
var keys = aDictionary._keys,
index = 0,
count = keys.length;
@@ -96,7 +96,7 @@ function dictionary_removeValue(aDictionary, aKey)
}
}
delete aDictionary.buckets[aKey];
delete aDictionary._buckets[aKey];
}
function dictionary_replaceValue(aDictionary, aKey, aValue)
@@ -111,8 +111,8 @@ function dictionary_replaceValue(aDictionary, aKey, aValue)
function dictionary_description(aDictionary)
{
str = "{ ";
for ( x in aDictionary.buckets)
str += x + ":" + aDictionary.buckets[x] + ",";
for ( x in aDictionary._buckets)
str += x + ":" + aDictionary._buckets[x] + ",";
str += " }";
return str;