Skip to content

Commit

Permalink
Cambios realizados desde ISIS1225-Lib
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipus85 committed Mar 2, 2022
1 parent 7a26d68 commit f290f07
Show file tree
Hide file tree
Showing 23 changed files with 771 additions and 1,386 deletions.
2 changes: 1 addition & 1 deletion DISClib/ADT/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import sys
file_path = os.path.join(os.path.dirname(__file__), '../..')
file_path = os.path.join(os.path.dirname(__file__), '..', '..')
file_dir = os.path.dirname(os.path.realpath('__file__'))
sys.path.insert(0, os.path.abspath(file_path))
53 changes: 37 additions & 16 deletions DISClib/ADT/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"""

import config
from DISClib.DataStructures import graphstructure as gr
import importlib
assert config

"""
Expand All @@ -51,7 +51,8 @@ def newGraph(datastructure="ADJ_LIST",
Raises:
Exception
"""
return gr.newGraph(datastructure, directed, size, comparefunction)
gr = graphSelector(datastructure)
return gr.newGraph(size, comparefunction, directed, datastructure, gr)


def insertVertex(graph, vertex):
Expand All @@ -66,7 +67,7 @@ def insertVertex(graph, vertex):
Raises:
Exception
"""
return gr.insertVertex(graph, vertex)
return graph['datastructure'].insertVertex(graph, vertex)


def removeVertex(graph, vertex):
Expand All @@ -81,7 +82,7 @@ def removeVertex(graph, vertex):
Raises:
Exception
"""
return gr.removeVertex(graph, vertex)
return graph['datastructure'].removeVertex(graph, vertex)


def numVertices(graph):
Expand All @@ -96,7 +97,7 @@ def numVertices(graph):
Raises:
Exception
"""
return gr.numVertices(graph)
return graph['datastructure'].numVertices(graph)


def numEdges(graph):
Expand All @@ -111,7 +112,7 @@ def numEdges(graph):
Raises:
Exception
"""
return gr.numEdges(graph)
return graph['datastructure'].numEdges(graph)


def vertices(graph):
Expand All @@ -125,7 +126,7 @@ def vertices(graph):
Raises:
Exception
"""
return gr.vertices(graph)
return graph['datastructure'].vertices(graph)


def edges(graph):
Expand All @@ -140,7 +141,7 @@ def edges(graph):
Raises:
Exception
"""
return gr.edges(graph)
return graph['datastructure'].edges(graph)


def degree(graph, vertex):
Expand All @@ -156,7 +157,7 @@ def degree(graph, vertex):
Raises:
Exception
"""
return gr.degree(graph, vertex)
return graph['datastructure'].degree(graph, vertex)


def outdegree(graph, vertex):
Expand All @@ -172,7 +173,7 @@ def outdegree(graph, vertex):
Raises:
Exception
"""
return gr.outdegree(graph, vertex)
return graph['datastructure'].outdegree(graph, vertex)


def indegree(graph, vertex):
Expand All @@ -188,7 +189,7 @@ def indegree(graph, vertex):
Raises:
Exception
"""
return gr.indegree(graph, vertex)
return graph['datastructure'].indegree(graph, vertex)


def getEdge(graph, vertexa, vertexb):
Expand All @@ -205,7 +206,7 @@ def getEdge(graph, vertexa, vertexb):
Raises:
Exception
"""
return gr.getEdge(graph, vertexa, vertexb)
return graph['datastructure'].getEdge(graph, vertexa, vertexb)


def addEdge(graph, vertexa, vertexb, weight=0):
Expand All @@ -226,7 +227,7 @@ def addEdge(graph, vertexa, vertexb, weight=0):
Raises:
Exception
"""
return gr.addEdge(graph, vertexa, vertexb, weight)
return graph['datastructure'].addEdge(graph, vertexa, vertexb, weight)


def containsVertex(graph, vertex):
Expand All @@ -242,7 +243,7 @@ def containsVertex(graph, vertex):
Raises:
Exception
"""
return gr.containsVertex(graph, vertex)
return graph['datastructure'].containsVertex(graph, vertex)


def adjacents(graph, vertex):
Expand All @@ -258,7 +259,7 @@ def adjacents(graph, vertex):
Raises:
Exception
"""
return gr.adjacents(graph, vertex)
return graph['datastructure'].adjacents(graph, vertex)


def adjacentEdges(graph, vertex):
Expand All @@ -275,4 +276,24 @@ def adjacentEdges(graph, vertex):
Raises:
Exception
"""
return gr.adjacentEdges(graph, vertex)
return graph['datastructure'].adjacentEdges(graph, vertex)


"""
Selector dinamico de la estructua de datos solicitada
"""

switch_module = {
"ADJ_LIST": ".adjlist",
"ADJ_MTX": ".adjlist",
}


def graphSelector(datastructure):
"""
Carga dinamicamente el import de la estructura de datos
seleccionada
"""
ds = switch_module.get(datastructure)
module = importlib.import_module(ds, package="DISClib.DataStructures")
return module
67 changes: 48 additions & 19 deletions DISClib/ADT/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"""

import config
import importlib
from DISClib.Utils import error as error
from DISClib.DataStructures import liststructure as lt
assert config


Expand All @@ -46,7 +46,8 @@ def newList(datastructure='SINGLE_LINKED',
Args:
datastructure: Tipo de estructura de datos a utilizar para implementar
la lista. Los tipos posibles pueden ser: ARRAY_LIST y SINGLE_LINKED.
la lista. Los tipos posibles pueden ser: ARRAY_LIST,
SINGLE_LINKED y DOUBLE_LINKED.
cmpfunction: Función de comparación para los elementos de la lista.
Si no se provee función de comparación se utiliza la función
Expand All @@ -69,7 +70,14 @@ def newList(datastructure='SINGLE_LINKED',
Exception
"""
try:
lst = lt.newList(datastructure, cmpfunction, key, filename, delimiter)
module = listSelector(datastructure)
lst = module.newList(
cmpfunction,
module,
key,
filename,
delimiter
)
return lst
except Exception as exp:
error.reraise(exp, 'TADList->newList: ')
Expand All @@ -93,7 +101,7 @@ def addFirst(lst, element):
Exception
"""
try:
lt.addFirst(lst, element)
lst['datastructure'].addFirst(lst, element)
except Exception as exp:
error.reraise(exp, 'TADList->addFirst: ')

Expand All @@ -112,7 +120,7 @@ def addLast(lst, element):
Exception
"""
try:
lt.addLast(lst, element)
lst['datastructure'].addLast(lst, element)
except Exception as exp:
error.reraise(exp, 'TADList->addLast: ')

Expand All @@ -127,7 +135,7 @@ def isEmpty(lst):
Exception
"""
try:
return lt.isEmpty(lst)
return lst['datastructure'].isEmpty(lst)
except Exception as exp:
error.reraise(exp, 'TADList->isEmpty: ')

Expand All @@ -142,7 +150,7 @@ def size(lst):
Exception
"""
try:
return lt.size(lst)
return lst['datastructure'].size(lst)
except Exception as exp:
error.reraise(exp, 'TADList->size: ')

Expand All @@ -158,7 +166,7 @@ def firstElement(lst):
Exception
"""
try:
return lt.firstElement(lst)
return lst['datastructure'].firstElement(lst)
except Exception as exp:
error.reraise(exp, 'TADList->firstElement: ')

Expand All @@ -174,7 +182,7 @@ def lastElement(lst):
Exception
"""
try:
return lt.lastElement(lst)
return lst['datastructure'].lastElement(lst)
except Exception as exp:
error.reraise(exp, 'TADList->LastElement: ')

Expand All @@ -195,7 +203,7 @@ def getElement(lst, pos):
Exception
"""
try:
return lt.getElement(lst, pos)
return lst['datastructure'].getElement(lst, pos)
except Exception as exp:
error.reraise(exp, 'List->getElement: ')

Expand All @@ -216,7 +224,7 @@ def deleteElement(lst, pos):
Exception
"""
try:
lt.deleteElement(lst, pos)
lst['datastructure'].deleteElement(lst, pos)
except Exception as exp:
error.reraise(exp, 'TADList->deleteElement: ')

Expand All @@ -237,7 +245,7 @@ def removeFirst(lst):
Exception
"""
try:
return lt.removeFirst(lst)
return lst['datastructure'].removeFirst(lst)
except Exception as exp:
error.reraise(exp, 'TADList->removeFirst: ')

Expand All @@ -258,7 +266,7 @@ def removeLast(lst):
Exception
"""
try:
return lt.removeLast(lst)
return lst['datastructure'].removeLast(lst)
except Exception as exp:
error.reraise(exp, 'TADList->removeLast: ')

Expand All @@ -280,7 +288,7 @@ def insertElement(lst, element, pos):
Exception
"""
try:
lt.insertElement(lst, element, pos)
lst['datastructure'].insertElement(lst, element, pos)
except Exception as exp:
error.reraise(exp, 'TADList->insertElement: ')

Expand All @@ -302,7 +310,7 @@ def isPresent(lst, element):
Exception
"""
try:
return lt.isPresent(lst, element)
return lst['datastructure'].isPresent(lst, element)
except Exception as exp:
error.reraise(exp, 'TADList->isPresent: ')

Expand All @@ -319,7 +327,7 @@ def exchange(lst, pos1, pos2):
Exception
"""
try:
lt.exchange(lst, pos1, pos2)
lst['datastructure'].exchange(lst, pos1, pos2)
except Exception as exp:
error.reraise(exp, 'List->exchange: ')

Expand All @@ -338,7 +346,7 @@ def changeInfo(lst, pos, element):
Exception
"""
try:
lt.changeInfo(lst, pos, element)
lst['datastructure'].changeInfo(lst, pos, element)
except Exception as exp:
error.reraise(exp, 'List->changeInfo: ')

Expand All @@ -359,7 +367,7 @@ def subList(lst, pos, numelem):
Exception
"""
try:
return lt.subList(lst, pos, numelem)
return lst['datastructure'].subList(lst, pos, numelem)
except Exception as exp:
error.reraise(exp, 'List->subList: ')

Expand All @@ -373,6 +381,27 @@ def iterator(lst):
Exception
"""
try:
return lt.iterator(lst)
return lst['datastructure'].iterator(lst)
except Exception as exp:
error.reraise(exp, 'List->Iterator: ')


"""
Selector dinamico de la estructua de datos solicitada
"""

switch_module = {
"ARRAY_LIST": ".arraylist",
"SINGLE_LINKED": ".singlelinkedlist",
"DOUBLE_LINKED": ".doublelinkedlist"
}


def listSelector(datastructure):
"""
Carga dinamicamente el import de la estructura de datos
seleccionada
"""
ds = switch_module.get(datastructure)
module = importlib.import_module(ds, package="DISClib.DataStructures")
return module
Loading

0 comments on commit f290f07

Please sign in to comment.