Subversion Repositories programming

Rev

Rev 10 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 11
Line 62... Line 62...
62
    //               return the value that was there if we updated a value
62
    //               return the value that was there if we updated a value
63
    //               return null if the table overflows (should never happen,
63
    //               return null if the table overflows (should never happen,
64
    //               but it is there just in case)
64
    //               but it is there just in case)
65
    public Object put(Object key, Object value) {
65
    public Object put(Object key, Object value) {
66
        if (used>loadFactor*entries.length) rehash();
66
        if (used>loadFactor*entries.length) rehash();
-
 
67
        
-
 
68
	System.out.print(key); //print out the key
-
 
69
	
67
        int h=hash(key); //hash the key
70
	int h=hash(key); //hash the key
-
 
71
        
68
        for (int i=0; i<entries.length; i++) { //run once for each place in the Table
72
	for (int i=0; i<entries.length; i++) { //run once for each place in the Table
69
            int j = nextProbe(h,i); //get the [first, next] place to try putting the value
73
            int j = nextProbe(h,i); //get the [first, next] place to try putting the value
70
            Entry entry=entries[j]; //get the Entry at j (where we want to put value)
74
            Entry entry=entries[j]; //get the Entry at j (where we want to put value)
71
            
75
            
-
 
76
	    System.out.print(" -> " + j); //print the location we tried to place the value
-
 
77
	    
72
	    //if entry[j] == null then we have found a good place to put value!
78
	    //if entry[j] == null then we have found a good place to put value!
73
	    if (entry==null) {
79
	    if (entry==null) {
-
 
80
 
-
 
81
                System.out.println(); //terminate the line
-
 
82
	    
74
                entries[j] = new Entry(key,value);
83
                entries[j] = new Entry(key,value);
75
                ++size;
84
                ++size;
76
                ++used;
85
                ++used;
77
                return null;  // insertion success
86
                return null;  // insertion success
78
            }
87
            }