Overview
Comment: | Add - hash for OFArray and OFString, main implementation in OFMacros. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ffd26c8238c2adb8b6090ae71d379c5b |
User & Date: | js on 2009-02-27 11:17:54 |
Other Links: | manifest | tags |
Context
2009-02-27
| ||
12:31 | (void)initialize -> initialize. check-in: 3b62c10b6f user: js tags: trunk | |
11:17 | Add - hash for OFArray and OFString, main implementation in OFMacros. check-in: ffd26c8238 user: js tags: trunk | |
2009-02-15
| ||
16:40 | Get rid of OFComparable and make it part of OFObject. check-in: d9308adc2b user: js tags: trunk | |
Changes
Modified src/OFArray.m from [3ecf264b3e] to [b65574e4bc].
︙ | |||
161 162 163 164 165 166 167 168 169 170 171 172 173 174 | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | + + + + + + + + + + + + + | } else { if ((ret = memcmp(data, [obj data], items * itemsize))) return ret; return *(char*)[obj item: [self items]] * -1; } } - (uint32_t)hash { uint32_t hash; size_t i; OF_HASH_INIT(hash); for (i = 0; i < items * itemsize; i++) OF_HASH_ADD(hash, ((char*)data)[i]); OF_HASH_FINALIZE(hash); return hash; } @end @implementation OFBigArray - initWithItemSize: (size_t)is { if (lastpagebyte == 0) lastpagebyte = getpagesize() - 1; |
︙ |
Modified src/OFMacros.h from [fd3e18f82c] to [ec8a81722f].
︙ | |||
38 39 40 41 42 43 44 | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | + + + + + + + + + + + + + + | } #else #define OF_BSWAP_V(buf, len) #endif #define OF_ROL(val, bits) \ (((val) << (bits)) | ((val) >> (32 - (bits)))) #define OF_HASH_INIT(hash) hash = 0 #define OF_HASH_ADD(hash, byte) \ { \ hash += byte; \ hash += (hash << 10); \ hash ^= (hash >> 6); \ } #define OF_HASH_FINALIZE(hash) \ { \ hash += (hash << 3); \ hash ^= (hash >> 11); \ hash += (hash << 15); \ } |
Modified src/OFObject.m from [091b00dab8] to [b132f8aa53].
︙ | |||
77 78 79 80 81 82 83 | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | - + | /* Classes containing data should reimplement this! */ return (self == obj ? YES : NO); } - (uint32_t)hash { /* Classes containing data should reimplement this! */ |
︙ |
Modified src/OFString.m from [6c57bbac26] to [504b483064].
︙ | |||
283 284 285 286 287 288 289 290 291 292 293 294 295 296 | 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | + + + + + + + + + + + + + | - (int)compare: (id)obj { if (![obj isKindOf: [OFString class]]) @throw [OFInvalidArgumentException newWithClass: [self class]]; return strcmp(string, [obj cString]); } - (uint32_t)hash { uint32_t hash; size_t i; OF_HASH_INIT(hash); for (i = 0; i < length; i++) OF_HASH_ADD(hash, string[i]); OF_HASH_FINALIZE(hash); return hash; } - append: (OFString*)str { return [self appendCString: [str cString]]; } - appendCString: (const char*)str |
︙ |
Modified tests/OFArray/OFArray.m from [95c48806f0] to [c4671d9ef0].
︙ | |||
131 132 133 134 135 136 137 138 139 140 | 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | + + + + + - - + + - + - + - + + + + + + | x = [OFArray arrayWithItemSize: 1]; y = [OFArray bigArrayWithItemSize: 1]; if (![x isEqual: y]) { puts("FAIL 1!"); return 1; } if ([x hash] != [y hash]) { puts("FAIL 2!"); return 1; } [x add: "x"]; if ([x isEqual: y]) { |
Modified tests/OFString/OFString.m from [0abd9793f1] to [06121ecfbf].
︙ | |||
21 22 23 24 25 26 27 | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | - + | #ifndef _WIN32 #define ZD "%zd" #else #define ZD "%u" #endif |
︙ | |||
60 61 62 63 64 65 66 | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | - + + + | OFString *s2 = [OFString stringWithCString: ""]; OFString *s3; OFString *s4 = [OFString string]; s3 = [s1 copy]; CHECK([s1 isEqual: s3]) |
︙ |