comparison SMART/Java/Python/structure/Bins.py @ 6:769e306b7933

Change the repository level.
author yufei-luo
date Fri, 18 Jan 2013 04:54:14 -0500
parents
children
comparison
equal deleted inserted replaced
5:ea3082881bf8 6:769e306b7933
1 #
2 # Copyright INRA-URGI 2009-2010
3 #
4 # This software is governed by the CeCILL license under French law and
5 # abiding by the rules of distribution of free software. You can use,
6 # modify and/ or redistribute the software under the terms of the CeCILL
7 # license as circulated by CEA, CNRS and INRIA at the following URL
8 # "http://www.cecill.info".
9 #
10 # As a counterpart to the access to the source code and rights to copy,
11 # modify and redistribute granted by the license, users are provided only
12 # with a limited warranty and the software's author, the holder of the
13 # economic rights, and the successive licensors have only limited
14 # liability.
15 #
16 # In this respect, the user's attention is drawn to the risks associated
17 # with loading, using, modifying and/or developing or reproducing the
18 # software by the user in light of its specific status of free software,
19 # that may mean that it is complicated to manipulate, and that also
20 # therefore means that it is reserved for developers and experienced
21 # professionals having in-depth computer knowledge. Users are therefore
22 # encouraged to load and test the software's suitability as regards their
23 # requirements in conditions enabling the security of their systems and/or
24 # data to be ensured and, more generally, to use and operate it in the
25 # same conditions as regards security.
26 #
27 # The fact that you are presently reading this means that you have had
28 # knowledge of the CeCILL license and that you accept its terms.
29 #
30 """
31 Some functions about bins
32 """
33
34 def getMinBin():
35 return 3
36
37
38 def getMaxBin():
39 return 7
40
41
42 def getBin(start, end):
43 for i in range(getMinBin(), getMaxBin() + 1):
44 binLevel = 10 ** i
45 if int(start / binLevel) == int(end / binLevel):
46 return int(i * 10 ** (getMaxBin() + 1) + int(start / binLevel))
47 return int((getMaxBin() + 1) * 10 ** (getMaxBin() + 1))
48
49
50 def getOverlappingBins(start, end):
51 array = []
52 bigBin = int((getMaxBin() + 1) * 10 ** (getMaxBin() + 1))
53 for i in range(getMinBin(), getMaxBin() + 1):
54 binLevel = 10 ** i
55 array.append((int(i * 10 ** (getMaxBin() + 1) + int(start / binLevel)), int(i * 10 ** (getMaxBin() + 1) + int(end / binLevel))))
56 array.append((bigBin, bigBin))
57 return array
58
59
60 def getIterator(maxValue = None):
61 if maxValue == None:
62 maxValue = 10 ** (getMaxBin() + getMinBin()) - 1
63 for i in range(getMinBin(), getMaxBin() + 1):
64 binLevel = 10 ** i
65 binBit = i * 10 ** (getMaxBin() + 1)
66 for j in range(0, maxValue / binLevel+1):
67 yield binBit + j
68 yield int((getMaxBin() + 1) * 10 ** (getMaxBin() + 1))
69
70
71 def getNbBins(maxValue = None):
72 if maxValue == None:
73 maxValue = 10 ** (getMaxBin() + getMinBin()) - 1
74 nbBins = 0
75 for i in range(getMinBin(), getMaxBin() + 1):
76 nbBins += maxValue / 10 ** i
77 return nbBins + 1