mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2024-12-26 01:29:10 +00:00
Array v 1.0.1
This commit is contained in:
parent
eb767d9967
commit
59783b79f7
@ -4,9 +4,11 @@
|
|||||||
# this should be imported as a python module using 'from tra_analysis import Array'
|
# this should be imported as a python module using 'from tra_analysis import Array'
|
||||||
# setup:
|
# setup:
|
||||||
|
|
||||||
__version__ = "1.0.0"
|
__version__ = "1.0.1"
|
||||||
|
|
||||||
__changelog__ = """changelog:
|
__changelog__ = """changelog:
|
||||||
|
1.0.1:
|
||||||
|
- removed search and __search functions
|
||||||
1.0.0:
|
1.0.0:
|
||||||
- ported analysis.Array() here
|
- ported analysis.Array() here
|
||||||
"""
|
"""
|
||||||
@ -118,35 +120,3 @@ class Array(): # tests on nd arrays independent of basic_stats
|
|||||||
left = self.sort(left)
|
left = self.sort(left)
|
||||||
right = self.sort(right)
|
right = self.sort(right)
|
||||||
return self.__merge(left, right)
|
return self.__merge(left, right)
|
||||||
|
|
||||||
|
|
||||||
def __merge(self, left, right):
|
|
||||||
sorted_list = []
|
|
||||||
left = left[:]
|
|
||||||
right = right[:]
|
|
||||||
while len(left) > 0 or len(right) > 0:
|
|
||||||
if len(left) > 0 and len(right) > 0:
|
|
||||||
if left[0] <= right[0]:
|
|
||||||
sorted_list.append(left.pop(0))
|
|
||||||
else:
|
|
||||||
sorted_list.append(right.pop(0))
|
|
||||||
elif len(left) > 0:
|
|
||||||
sorted_list.append(left.pop(0))
|
|
||||||
elif len(right) > 0:
|
|
||||||
sorted_list.append(right.pop(0))
|
|
||||||
return sorted_list
|
|
||||||
|
|
||||||
def search(self, arr, x):
|
|
||||||
return self.__search(arr, 0, len(arr) - 1, x)
|
|
||||||
|
|
||||||
def __search(self, arr, low, high, x):
|
|
||||||
if high >= low:
|
|
||||||
mid = (high + low) // 2
|
|
||||||
if arr[mid] == x:
|
|
||||||
return mid
|
|
||||||
elif arr[mid] > x:
|
|
||||||
return binary_search(arr, low, mid - 1, x)
|
|
||||||
else:
|
|
||||||
return binary_search(arr, mid + 1, high, x)
|
|
||||||
else:
|
|
||||||
return -1
|
|
||||||
|
Loading…
Reference in New Issue
Block a user