Skip to main content
se eliminaron 352 caracteres en el cuerpo
Origen Enlace
public Memory bestSlot(@NotNull Process process) {

    int i = 0;
    int position=0;
    boolean allowed = false;
    Slot oldSlot = new Slot(size,i);
    Slot bestSlot = new Slot(size+1,i);

    // if there's no more space we will return false
    if(!isSpace(process.getMemory()) || containsProcess(process)) {
        return null;
    }

    // for every Pair of key,value we will search for the optimal slot
    for (Map.Entry<Slot,Process> pairEntry: memory.entrySet() ) {
 
        // if we find a slot with the same value as the space we want to divide, and it is empty then
        if (pairEntry.getValue()==null){
            // if it's the same amount of space we will assign the process to this slot
            if (( pairEntry.getKey()).getSpace() == process.getMemory()){
                process.setSlot(pairEntry.getKey());
                process.setPosition(pairEntry.getKey().getX());
                memory.put((pairEntry.getKey()),process);

                return this;
            }
            // else if the space in this slot is bigger then...
            else if ((pairEntry.getKey()).getSpace() > process.getMemory()){
                // ifsi theel auxiliarytamaño Slotdel sizehueco isauxiliar stillsigue bigger,siendo thengrande, replaceentonces forreemplazar thispor oneeste
                if(bestSlot.getSpace() > (pairEntry.getKey()).getSpace()){
                    allowed = true;
                    oldSlot=pairEntry.getKey();
                    position = (pairEntry.getKey()).getX();

                    bestSlot.setSpace(process.getMemory());
                    bestSlot.setX(i);
                    //memory.remove(((Slot) pairEntry.getKey()));

                }
            }
        }

        i++;
    }

    if (allowed){
        pushSlots(position+1);
        // we remove the sloteliminamos thatel willhueco beque replacedva bya theser subtractionreemplazado ofpor theel newresto space
        memory.remove(oldSlot,null);
        oldSlot.setSpace(oldSlot.getSpace()-process.getMemory());
        oldSlot.setX(position+1);
        memory.put(oldSlot,null);
        process.setSlot(bestSlot);
        memory.put(bestSlot,process);
    }

    return this;
}
public Memory bestSlot(@NotNull Process process) {

    int i = 0;
    int position=0;
    boolean allowed = false;
    Slot oldSlot = new Slot(size,i);
    Slot bestSlot = new Slot(size+1,i);

    // if there's no more space we will return false
    if(!isSpace(process.getMemory()) || containsProcess(process)) {
        return null;
    }

    // for every Pair of key,value we will search for the optimal slot
    for (Map.Entry<Slot,Process> pairEntry: memory.entrySet() ) {
 
        // if we find a slot with the same value as the space we want to divide, and it is empty then
        if (pairEntry.getValue()==null){
            // if it's the same amount of space we will assign the process to this slot
            if (( pairEntry.getKey()).getSpace() == process.getMemory()){
                process.setSlot(pairEntry.getKey());
                process.setPosition(pairEntry.getKey().getX());
                memory.put((pairEntry.getKey()),process);

                return this;
            }
            // else if the space in this slot is bigger then...
            else if ((pairEntry.getKey()).getSpace() > process.getMemory()){
                // if the auxiliary Slot size is still bigger, then replace for this one
                if(bestSlot.getSpace() > (pairEntry.getKey()).getSpace()){
                    allowed = true;
                    oldSlot=pairEntry.getKey();
                    position = (pairEntry.getKey()).getX();

                    bestSlot.setSpace(process.getMemory());
                    bestSlot.setX(i);
                    //memory.remove(((Slot) pairEntry.getKey()));

                }
            }
        }

        i++;
    }

    if (allowed){
        pushSlots(position+1);
        // we remove the slot that will be replaced by the subtraction of the new space
        memory.remove(oldSlot,null);
        oldSlot.setSpace(oldSlot.getSpace()-process.getMemory());
        oldSlot.setX(position+1);
        memory.put(oldSlot,null);
        process.setSlot(bestSlot);
        memory.put(bestSlot,process);
    }

    return this;
}
public Memory bestSlot(@NotNull Process process) {

    int i = 0;
    int position=0;
    boolean allowed = false;
    Slot oldSlot = new Slot(size,i);
    Slot bestSlot = new Slot(size+1,i);

    if(!isSpace(process.getMemory()) || containsProcess(process)) {
        return null;
    }

    for (Map.Entry<Slot,Process> pairEntry: memory.entrySet() ) {

        if (pairEntry.getValue()==null){
            
            if (( pairEntry.getKey()).getSpace() == process.getMemory()){
                process.setSlot(pairEntry.getKey());
                process.setPosition(pairEntry.getKey().getX());
                memory.put((pairEntry.getKey()),process);

                return this;
            }
            
            else if ((pairEntry.getKey()).getSpace() > process.getMemory()){
                // si el tamaño del hueco auxiliar sigue siendo grande, entonces reemplazar por este
                if(bestSlot.getSpace() > (pairEntry.getKey()).getSpace()){
                    allowed = true;
                    oldSlot=pairEntry.getKey();
                    position = (pairEntry.getKey()).getX();

                    bestSlot.setSpace(process.getMemory());
                    bestSlot.setX(i);
                    //memory.remove(((Slot) pairEntry.getKey()));

                }
            }
        }

        i++;
    }

    if (allowed){
        pushSlots(position+1);
        // eliminamos el hueco que va a ser reemplazado por el resto 
        memory.remove(oldSlot,null);
        oldSlot.setSpace(oldSlot.getSpace()-process.getMemory());
        oldSlot.setX(position+1);
        memory.put(oldSlot,null);
        process.setSlot(bestSlot);
        memory.put(bestSlot,process);
    }

    return this;
}
se añadieron 2159 caracteres en el cuerpo
Origen Enlace

El método de bestSlot es el siguiente:

public Memory bestSlot(@NotNull Process process) {

    int i = 0;
    int position=0;
    boolean allowed = false;
    Slot oldSlot = new Slot(size,i);
    Slot bestSlot = new Slot(size+1,i);

    // if there's no more space we will return false
    if(!isSpace(process.getMemory()) || containsProcess(process)) {
        return null;
    }

    // for every Pair of key,value we will search for the optimal slot
    for (Map.Entry<Slot,Process> pairEntry: memory.entrySet() ) {

        // if we find a slot with the same value as the space we want to divide, and it is empty then
        if (pairEntry.getValue()==null){
            // if it's the same amount of space we will assign the process to this slot
            if (( pairEntry.getKey()).getSpace() == process.getMemory()){
                process.setSlot(pairEntry.getKey());
                process.setPosition(pairEntry.getKey().getX());
                memory.put((pairEntry.getKey()),process);

                return this;
            }
            // else if the space in this slot is bigger then...
            else if ((pairEntry.getKey()).getSpace() > process.getMemory()){
                // if the auxiliary Slot size is still bigger, then replace for this one
                if(bestSlot.getSpace() > (pairEntry.getKey()).getSpace()){
                    allowed = true;
                    oldSlot=pairEntry.getKey();
                    position = (pairEntry.getKey()).getX();

                    bestSlot.setSpace(process.getMemory());
                    bestSlot.setX(i);
                    //memory.remove(((Slot) pairEntry.getKey()));

                }
            }
        }

        i++;
    }

    if (allowed){
        pushSlots(position+1);
        // we remove the slot that will be replaced by the subtraction of the new space
        memory.remove(oldSlot,null);
        oldSlot.setSpace(oldSlot.getSpace()-process.getMemory());
        oldSlot.setX(position+1);
        memory.put(oldSlot,null);
        process.setSlot(bestSlot);
        memory.put(bestSlot,process);
    }

    return this;
}

Dicho método analiza los mejores huecos que existen para cada proceso que se pasa por parámetro, haciendo los ajustes necesarios tales como dejar el resto del espacio que está ocupando y si es necesario hacer un push con los elementos del mapa que están por delante

El método de bestSlot es el siguiente:

public Memory bestSlot(@NotNull Process process) {

    int i = 0;
    int position=0;
    boolean allowed = false;
    Slot oldSlot = new Slot(size,i);
    Slot bestSlot = new Slot(size+1,i);

    // if there's no more space we will return false
    if(!isSpace(process.getMemory()) || containsProcess(process)) {
        return null;
    }

    // for every Pair of key,value we will search for the optimal slot
    for (Map.Entry<Slot,Process> pairEntry: memory.entrySet() ) {

        // if we find a slot with the same value as the space we want to divide, and it is empty then
        if (pairEntry.getValue()==null){
            // if it's the same amount of space we will assign the process to this slot
            if (( pairEntry.getKey()).getSpace() == process.getMemory()){
                process.setSlot(pairEntry.getKey());
                process.setPosition(pairEntry.getKey().getX());
                memory.put((pairEntry.getKey()),process);

                return this;
            }
            // else if the space in this slot is bigger then...
            else if ((pairEntry.getKey()).getSpace() > process.getMemory()){
                // if the auxiliary Slot size is still bigger, then replace for this one
                if(bestSlot.getSpace() > (pairEntry.getKey()).getSpace()){
                    allowed = true;
                    oldSlot=pairEntry.getKey();
                    position = (pairEntry.getKey()).getX();

                    bestSlot.setSpace(process.getMemory());
                    bestSlot.setX(i);
                    //memory.remove(((Slot) pairEntry.getKey()));

                }
            }
        }

        i++;
    }

    if (allowed){
        pushSlots(position+1);
        // we remove the slot that will be replaced by the subtraction of the new space
        memory.remove(oldSlot,null);
        oldSlot.setSpace(oldSlot.getSpace()-process.getMemory());
        oldSlot.setX(position+1);
        memory.put(oldSlot,null);
        process.setSlot(bestSlot);
        memory.put(bestSlot,process);
    }

    return this;
}

Dicho método analiza los mejores huecos que existen para cada proceso que se pasa por parámetro, haciendo los ajustes necesarios tales como dejar el resto del espacio que está ocupando y si es necesario hacer un push con los elementos del mapa que están por delante

se eliminaron 1096 caracteres en el cuerpo
Origen Enlace
Alfabravo
  • 9.9k
  • 5
  • 24
  • 32

HELPP My array is updating every element behind while updating a single element Por qué el arreglo actualiza cada elemento cuando actualizo un elemento?


I'm trying to update an element of an array every iteration but it keeps setting the same value for every element behind.

It gives me this output:

[ ( 0: 800 | Process: p1)  ( 1: 200 | Process: p2)  ( 2: 200 | Process: p3)  ( 3: 800 ) ]
[ ( 0: 800 | Process: p1)  ( 1: 200 | Process: p2)  ( 2: 200 | Process: p3)  ( 3: 800 ) ]
[ ( 0: 800 | Process: p1)  ( 1: 200 | Process: p2)  ( 2: 200 | Process: p3)  ( 3: 800 ) ]

While it should be something like this:

[ ( 0: 800 | Process: p1)  ( 1: 1200 ) ] 
[ ( 0: 800 | Process: p1)  ( 1: 200 | Process: p2)  ( 2: 1000 ) ] 
[ ( 0: 800 | Process: p1)  ( 1: 200 | Process: p2)  ( 2: 200 | Process: p3)  ( 3: 800 ) ]

The changes start while updating the content of memory of each iteration (in this case with bestSlot but it shouldn't have access to the other elements itself). While creating a new instance of Memory it creates a single slot with 2000 as value and no process assigned

Here's the full code: repository


HELPP My array is updating every element behind while updating a single element


I'm trying to update an element of an array every iteration but it keeps setting the same value for every element behind.

It gives me this output:

[ ( 0: 800 | Process: p1)  ( 1: 200 | Process: p2)  ( 2: 200 | Process: p3)  ( 3: 800 ) ]
[ ( 0: 800 | Process: p1)  ( 1: 200 | Process: p2)  ( 2: 200 | Process: p3)  ( 3: 800 ) ]
[ ( 0: 800 | Process: p1)  ( 1: 200 | Process: p2)  ( 2: 200 | Process: p3)  ( 3: 800 ) ]

While it should be something like this:

[ ( 0: 800 | Process: p1)  ( 1: 1200 ) ] 
[ ( 0: 800 | Process: p1)  ( 1: 200 | Process: p2)  ( 2: 1000 ) ] 
[ ( 0: 800 | Process: p1)  ( 1: 200 | Process: p2)  ( 2: 200 | Process: p3)  ( 3: 800 ) ]

The changes start while updating the content of memory of each iteration (in this case with bestSlot but it shouldn't have access to the other elements itself). While creating a new instance of Memory it creates a single slot with 2000 as value and no process assigned

Here's the full code: repository


Por qué el arreglo actualiza cada elemento cuando actualizo un elemento?

se añadieron 108 caracteres en el cuerpo
Origen Enlace
Loading
se añadieron 108 caracteres en el cuerpo
Origen Enlace
Loading
Origen Enlace
Loading