Changeset 12209
- Timestamp:
- Mar 22, 2011, 11:42:25 PM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-msgs.c
r12204 r12209 2105 2105 diffs->elements[diffs->elementCount++] = *pex; 2106 2106 } 2107 2108 /** 2109 * @brief find the differences and commonalities in two sorted sets 2110 * @param a the first set 2111 * @param aCount the number of elements in the set 'a' 2112 * @param b the second set 2113 * @param bCount the number of elements in the set 'b' 2114 * @param compare the sorting method for both sets 2115 * @param elementSize the sizeof the element in the two sorted sets 2116 * @param in_a called for items in set 'a' but not set 'b' 2117 * @param in_b called for items in set 'b' but not set 'a' 2118 * @param in_both called for items that are in both sets 2119 * @param userData user data passed along to in_a, in_b, and in_both 2120 */ 2121 static void 2122 tr_set_compare( const void * va, size_t aCount, 2123 const void * vb, size_t bCount, 2124 int compare( const void * a, const void * b ), 2125 size_t elementSize, 2126 tr_set_func in_a_cb, 2127 tr_set_func in_b_cb, 2128 tr_set_func in_both_cb, 2129 void * userData ) 2130 { 2131 const uint8_t * a = va; 2132 const uint8_t * b = vb; 2133 const uint8_t * aend = a + elementSize * aCount; 2134 const uint8_t * bend = b + elementSize * bCount; 2135 2136 while( a != aend || b != bend ) 2137 { 2138 if( a == aend ) 2139 { 2140 ( *in_b_cb )( (void*)b, userData ); 2141 b += elementSize; 2142 } 2143 else if( b == bend ) 2144 { 2145 ( *in_a_cb )( (void*)a, userData ); 2146 a += elementSize; 2147 } 2148 else 2149 { 2150 const int val = ( *compare )( a, b ); 2151 2152 if( !val ) 2153 { 2154 ( *in_both_cb )( (void*)a, userData ); 2155 a += elementSize; 2156 b += elementSize; 2157 } 2158 else if( val < 0 ) 2159 { 2160 ( *in_a_cb )( (void*)a, userData ); 2161 a += elementSize; 2162 } 2163 else if( val > 0 ) 2164 { 2165 ( *in_b_cb )( (void*)b, userData ); 2166 b += elementSize; 2167 } 2168 } 2169 } 2170 } 2171 2107 2172 2108 2173 static void -
trunk/libtransmission/utils.c
r12204 r12209 354 354 { 355 355 return memcpy( tr_malloc( byteCount ), src, byteCount ); 356 }357 358 /***359 ****360 ***/361 362 void363 tr_set_compare( const void * va, size_t aCount,364 const void * vb, size_t bCount,365 int compare( const void * a, const void * b ),366 size_t elementSize,367 tr_set_func in_a_cb,368 tr_set_func in_b_cb,369 tr_set_func in_both_cb,370 void * userData )371 {372 const uint8_t * a = va;373 const uint8_t * b = vb;374 const uint8_t * aend = a + elementSize * aCount;375 const uint8_t * bend = b + elementSize * bCount;376 377 while( a != aend || b != bend )378 {379 if( a == aend )380 {381 ( *in_b_cb )( (void*)b, userData );382 b += elementSize;383 }384 else if( b == bend )385 {386 ( *in_a_cb )( (void*)a, userData );387 a += elementSize;388 }389 else390 {391 const int val = ( *compare )( a, b );392 393 if( !val )394 {395 ( *in_both_cb )( (void*)a, userData );396 a += elementSize;397 b += elementSize;398 }399 else if( val < 0 )400 {401 ( *in_a_cb )( (void*)a, userData );402 a += elementSize;403 }404 else if( val > 0 )405 {406 ( *in_b_cb )( (void*)b, userData );407 b += elementSize;408 }409 }410 }411 356 } 412 357 -
trunk/libtransmission/utils.h
r12208 r12209 405 405 typedef void ( tr_set_func )( void * element, void * userData ); 406 406 407 /**408 * @brief find the differences and commonalities in two sorted sets409 * @param a the first set410 * @param aCount the number of elements in the set 'a'411 * @param b the second set412 * @param bCount the number of elements in the set 'b'413 * @param compare the sorting method for both sets414 * @param elementSize the sizeof the element in the two sorted sets415 * @param in_a called for items in set 'a' but not set 'b'416 * @param in_b called for items in set 'b' but not set 'a'417 * @param in_both called for items that are in both sets418 * @param userData user data passed along to in_a, in_b, and in_both419 */420 void tr_set_compare( const void * a, size_t aCount,421 const void * b, size_t bCount,422 int compare( const void * a, const void * b ),423 size_t elementSize,424 tr_set_func in_a_cb,425 tr_set_func in_b_cb,426 tr_set_func in_both_cb,427 void * userData );428 429 407 int compareInt( const void * va, const void * vb ); 430 408
Note: See TracChangeset
for help on using the changeset viewer.