
-----------------------------------
copthesaint
Wed Sep 30, 2009 4:12 pm

Holder Class
-----------------------------------
I made this holder class that stores type of type integer and double. 
I thought it would be interesting to use, anyways Please comment! :) 

 /*********************************************
  *Holder Class by: Christian Olienick Plourde*
  *********************************************
  *Designed to be used to hold values,        *
  *without having to declare variables.       *
  *********************************************
 */
 
    public class Holder {
    
      int[/syntax]

-----------------------------------
DemonWasp
Wed Sep 30, 2009 4:23 pm

RE:Holder Class
-----------------------------------
While that is certainly an impressive effort, why not just use Map, specifically HashMap ? It'd be way faster for pretty well every operation, uses less memory, and is built-in (it's part of the core Java API).

You also have a series of bugs: you cannot compare one string to another using == in Java. That comparison compares the values of their references, which is not what you want to do. You need to use string1.equals ( string2 ); or string1.equalsIgnoreCase ( string2 ); .

Asymptotic Comparison:
Insert: HashMap is O(1), yours is O(N)
Remove: HashMap is O(1), yours is O(N)
Set: HashMap is O(1), yours is O(N)
Iterate: HashMap is O(N), yours is O(N), but probably faster...if you had implemented this operation.
Max Capacity: HashMap is (whatever you can fit into the heap), yours is 10000.

You also don't need a main() method on a class that isn't going to be run as a program.

-----------------------------------
copthesaint
Thu Oct 01, 2009 1:34 pm

RE:Holder Class
-----------------------------------
Thanks, i didnt realise I needed to use .equals() all ways...So what I made is simular to the Hashmap Class? If so, what am I doing making this lol. Lastly what did you mean by O(N) and O(1).

-----------------------------------
DemonWasp
Thu Oct 01, 2009 2:04 pm

RE:Holder Class
-----------------------------------
What you've made implements some of the operations expected of a some expression on N ) are statements of the asymptotic time required by a given algorithm. Put more simply, they are the "Order" of the operation. So if I say something takes O(1) time, that means "constant time" - no matter how large N is, it should always take the same amount of time. Something which is O(N) will take an amount of time roughly proportional to the value of N. Something which is O ( N^2 ) takes an amount of time roughly proportional to N squared.


As you may imagine, lower orders will scale better (they will handle an increase in N more efficiently than a higher order algorithm). This doesn't necessarily imply that they run faster in all cases, but it does guarantee that for sufficiently large N, they will perform faster.


So when I say that your algorithm is O ( N ), I mean it gets slower in proportion to the number of objects you have in your arrays. If N is large, say N=8000, it will take 800 times longer than if N=10.

HashMap, on the other hand, is O ( 1 )* for all the operations you have implemented - get, remove and set. amortized O(1), which is a bit complex and best left for another day.
