def sortHash (catalog): #Iterar tabla de hash, extraer lista de llaves, ordenar cada lista de tuplas con mergeSort citiesList = map.keySet(catalog['capacityMap']) citiesIter = it.newIterator(citiesList) while it.hasNext(citiesIter): i_city = it.next(citiesIter) stationCapacityList = map.get(catalog['capacityMap'], i_city)['value'] mergesort.mergesort(stationCapacityList, compareByTuple)
def test_getkeys (self): """ """ ltset = lt.newList ('SINGLE_LINKED_LIST') ltset = ht.keySet(self.table) iterator = it.newIterator (ltset) while it.hasNext (iterator): info = it.next (iterator) print (info)
def tripCityforDates (catalog, start_date, end_date): start_date=strToDate(start_date, '%m/%d/%Y') #Convertir fecha end_date=strToDate(end_date, '%m/%d/%Y') #Convertir fecha dateList = oms.valueRange(catalog['dateTree'], start_date, end_date, greater) #Lista de llaves entre las fechas dadas response='' tripsCityDays = map.newMap(capacity=11, maptype='CHAINING') #Se almacenan if dateList: print(dateList) iteraDate=it.newIterator(dateList) while it.hasNext(iteraDate): dateElement = it.next(iteraDate) #print(dateElement) if oms.get(catalog['dateTree'],dateElement, greater):#Si el nodo tiene un valor asociado if map.isEmpty(tripsCityDays):#Si cities está vacío, se le asigna el map de accidentes por ciudad del primer nodo tripsCityDays = oms.get(catalog['dateTree'], dateElement, greater) else: #De lo contrario, se compara cada ciudad del map de cada nodo con el map ciudadesNodo = map.keySet(dateElement)#Lista de las ciudades que tuvieron accidentes en esa fecha(nodo) ciudadesCities = map.keySet(tripsCityDays) iteraCiudades = it.newIterator(ciudadesNodo) while it.hasNext(iteraCiudades): ciudadElement=it.next(iteraCiudades)# que está en el map de cada nodo if ciudadElement: if lt.isPresent(ciudadesCities, ciudadElement, compareByKey): #Se verifica si la ciudad está en los valores del map num=map.get(tripsCityDays, ciudadElement)['value'] num+=map.get(dateElement, ciudadElement)['value'] map.put(tripsCityDays, ciudadElement, num) else: num= map.get(dateElement, ciudadElement)['value'] map.put(dateElement, ciudadElement, num) if not map.isEmpty(tripsCityDays): cityList= map.keySet(tripsCityDays) iteracity=it.newIterator(cityList) while it.hasNext(iteracity): cityKey = it.next(iteracity) response += str(cityKey) + ':' + str(map.get(tripsCityDays,cityKey)['value']) + " " return response return None
def test_getkeys (self): """ """ table = ht.newMap (capacity= 7, maptype='CHAINING') ht.put (table, 'book1', 'title1', self.compareentryfunction) ht.put (table, 'book2', 'title2', self.compareentryfunction) ht.put (table, 'book3', 'title3', self.compareentryfunction) ht.put (table, 'book4', 'title4', self.compareentryfunction) ht.put (table, 'book5', 'title5', self.compareentryfunction) ht.put (table, 'book6', 'title6', self.compareentryfunction) ltset = ht.keySet(table) iterator = it.newIterator (ltset) while it.hasNext (iterator): info = it.next (iterator) print (info)
def test_getkeys(self): """ """ table = ht.newMap(capacity=17, maptype='PROBING') ht.put(table, '1', 'title1', self.comparekeys) ht.put(table, '2', 'title2', self.comparekeys) ht.put(table, '3', 'title3', self.comparekeys) ht.put(table, '4', 'title4', self.comparekeys) ht.put(table, '5', 'title5', self.comparekeys) ht.put(table, '6', 'title6', self.comparekeys) ltset = lt.newList('SINGLE_LINKED') ltset = ht.keySet(table) iterator = it.newIterator(ltset) while it.hasNext(iterator): info = it.next(iterator) print(info)
def test_getkeys(self): """ """ capacity = 10 table = ht.newMap(capacity, maptype='PROBING', comparefunction=self.comparekeys) ht.put(table, '1', 'title1') ht.put(table, '2', 'title2') ht.put(table, '11', 'title3') ht.put(table, '3', 'title4') ht.put(table, '12', 'title5') ht.put(table, '5', 'title6') ltset = lt.newList('SINGLE_LINKED_LIST') ltset = ht.keySet(table) iterator = it.newIterator(ltset) while it.hasNext(iterator): info = it.next(iterator) print(info)
def keySet(map): """ Retorna una lista con todas las llaves de la tabla de hash """ return ht.keySet(map)
def tripsPerTemperature(catalog, number): longList = lt.size(catalog['tempList']) leastTemp = lt.subList(catalog['tempList'],longList-number,number) mostTemp = lt.subList(catalog['tempList'], 1, number) #O(1) por ser array counter1 = 0 counter2 = 0 response1='' response2='' tripsMostTempDays = map.newMap(30, comparefunction=compareByKey) tripsLeastTempDays = map.newMap(30, comparefunction=compareByKey) while counter1<number: leastTempIterator = it.newIterator(leastTemp) #Iterar la lista con n menores temperaturas while it.hasNext(leastTempIterator): tempElement = it.next(leastTempIterator) #Temperatura dateListElement = map.get(catalog['temperatureHash'],tempElement)['value']#Lista de todas las fechas para esa temperatura if number - lt.size(dateListElement) < counter1: #si no se pueden agregar todas las fechas de esa temperatura sin alcanzar el n deseado n_dates = lt.subList(dateListElement, 1, number-counter1) #lista de las que si se pueden agragar n_iterator = it.newIterator(n_dates) while it.hasNext(n_iterator): n_dateElement = it.next(n_iterator) #fecha a agregar trips = oms.get(catalog['dateTree'], n_dateElement, greater) #hash de viajes de esa fecha #print(type(trips)) totaltrip = map.get(trips, 'total')['value'] #número de viajes totales en esa fecha value = (tempElement, totaltrip) #tupla que se asigna como valor de cada fecha: temperatura, viajes totales map.put(tripsLeastTempDays, n_dateElement, value) counter1 += lt.size(n_dates)#el número de fechas que se agregó se suma al counter else: #si se pueden agregar todas las fechas de esa temperatura sin alcanzar el n deseado n_dates = dateListElement #se recorre la lista completa n_iterator = it.newIterator(n_dates) while it.hasNext(n_iterator): n_dateElement = it.next(n_iterator) #fecha a agregar trips = oms.get(catalog['dateTree'], n_dateElement, greater) #print(type(trips)) totaltrip = map.get(trips, 'total')['value'] value = (tempElement, totaltrip) map.put(tripsLeastTempDays, n_dateElement, value) counter1 += lt.size(dateListElement) while counter2<number: mostTempIterator = it.newIterator(mostTemp) #Iterar la lista con n temperaturas más altas while it.hasNext(mostTempIterator): tempElement = it.next(mostTempIterator) dateListElement = map.get(catalog['temperatureHash'],tempElement)['value']#Lista de todas las fechas para esa temperatura if number - lt.size(dateListElement) < counter2: #si no se pueden agregar todas las fechas de esa temperatura sin alcanzar el n deseado n_dates = lt.subList(dateListElement, 1, number-counter2) n_iterator = it.newIterator(n_dates) while it.hasNext(n_iterator): n_dateElement = it.next(n_iterator) value = oms.get(catalog['dateTree'], n_dateElement, greater) value = map.get(value, 'total')['value'] value = (tempElement, value) map.put(tripsMostTempDays, n_dateElement, value) counter2 += lt.size(n_dates) else: #si se pueden agregar todas las fechas de esa temperatura sin alcanzar el n deseado n_dates = dateListElement n_iterator = it.newIterator(n_dates) while it.hasNext(n_iterator): n_dateElement = it.next(n_iterator) value = oms.get(catalog['dateTree'], n_dateElement, greater) value = map.get(value, 'total')['value'] value = (tempElement, value) map.put(tripsMostTempDays, n_dateElement, value) counter2 += lt.size(dateListElement) if not map.isEmpty(tripsMostTempDays): tempList= map.keySet(tripsMostTempDays) iteratemp=it.newIterator(tempList) while it.hasNext(iteratemp): tempKey = it.next(iteratemp) response1 += str(tempKey) + ':' + str(map.get(tripsMostTempDays,tempKey)['value']) + " " if not map.isEmpty(tripsLeastTempDays): tempList= map.keySet(tripsLeastTempDays) iteratemp=it.newIterator(tempList) while it.hasNext(iteratemp): tempKey = it.next(iteratemp) response2 += str(tempKey) + ':' + str(map.get(tripsLeastTempDays,tempKey)['value']) + " " return response1, response2
def tempAux (catalog): tempValues = map.keySet(catalog['temperatureHash']) mergesort.mergesort(tempValues, greater) catalog['tempList'] = tempValues