Abgabe Übungstest 5
This commit is contained in:
		@@ -65,16 +65,36 @@ public class MassiveForceHashMap {
 | 
			
		||||
     * Precondition: key != null.
 | 
			
		||||
     */
 | 
			
		||||
    public Vector3 get(Massive key) {
 | 
			
		||||
        int pos = find(key);
 | 
			
		||||
        return (pos == -1) ? null : values[pos];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int find(Massive key) {
 | 
			
		||||
        int idx = ((key.hashCode() % keys.length) + keys.length) % keys.length;
 | 
			
		||||
        for (int i = 0; i < keys.length; i++) {
 | 
			
		||||
            int pos = (idx + i) % keys.length;
 | 
			
		||||
            if (keys[pos] == null) {
 | 
			
		||||
                break;
 | 
			
		||||
            } else if (keys[pos].equals(key)) {
 | 
			
		||||
                return values[pos];
 | 
			
		||||
                return pos;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Deletes the mapping for the specified key from this map if present.
 | 
			
		||||
     * Returns the previous value associated with key, or null if there was
 | 
			
		||||
     * no mapping for key.
 | 
			
		||||
     * Precondition: key != null
 | 
			
		||||
     */
 | 
			
		||||
    public Vector3 delete(Massive key) {
 | 
			
		||||
        int pos = find(key);
 | 
			
		||||
        if (pos == -1) return null;
 | 
			
		||||
 | 
			
		||||
        Vector3 val = values[pos];
 | 
			
		||||
        values[pos] = null;
 | 
			
		||||
        return val;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user