1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: fslow_QueryOptimalBucketCount.cpp 4 5 Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev:$ 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