1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: fs_QueryOptimalBucketCount.cpp 4 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. 5 These coded instructions, statements, and computer programs contain 6 proprietary information of Nintendo of America Inc. and/or Nintendo 7 Company Ltd., and are protected by Federal copyright law. They may 8 not be disclosed to third parties or copied or duplicated in any form, 9 in whole or in part, without the prior written consent of Nintendo. 10 $Rev: 34454 $ 11 *--------------------------------------------------------------------------- 12 13 14 */ 15 16 #include <nn/fslow/fslow_QueryOptimalBucketCount.h> 17 18 namespace nn { namespace fslow { 19 QueryOptimalBucketCount(u32 countEntries)20u32 QueryOptimalBucketCount(u32 countEntries) 21 { 22 if (countEntries <= 3) 23 { 24 // When the number of entries is extremely small, return a fixed size for the packet number. 25 return 3; 26 } 27 if (countEntries <= 19) 28 { 29 // When the number of entries is less than 20, return an odd number 30 return countEntries | 1; 31 } 32 33 // When the number of entries exceeds 20, prune with small value prime numbers. 34 // 35 u32 i; 36 for (i = 0; i < 100; i++) 37 { 38 u32 candidate = (countEntries + i); 39 if ( 40 (candidate % 2) != 0 && 41 (candidate % 3) != 0 && 42 (candidate % 5) != 0 && 43 (candidate % 7) != 0 && 44 (candidate % 11) != 0 && 45 (candidate % 13) != 0 && 46 (candidate % 17) != 0 47 ) 48 { 49 return candidate; 50 } 51 } 52 return countEntries | 1; 53 } 54 55 }} 56