aspose file tools*
The moose likes Java in General and the fly likes Choosing the best data-sctructure for file storing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Choosing the best data-sctructure for file storing" Watch "Choosing the best data-sctructure for file storing" New topic
Author

Choosing the best data-sctructure for file storing

Yotam Ohayon
Greenhorn

Joined: Dec 31, 2010
Posts: 26
so
my program gets a directory, filter the files according to different filters, then perform several actions and return the files in a desired order.
i thought it is not necessary to order before i filter because then i would sort a lot of files for nothing. after the files are sorted i return them in a TreeSet.

so, my question is, what would be the best data structure to store the files before i put them in order? by best i mean in terms of run time of course.
thanks, yotam
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
There is no such thing as a best data structure. What do you intend to do with these files? I presume you are already familiar with the different kinds of Set, List, Queue and Map?
Yotam Ohayon
Greenhorn

Joined: Dec 31, 2010
Posts: 26
i don't REALLY know them and what are their advantages. until i sort the file, i want them all in one data structure so i can iterate through them and filter them.
i was wondering if there is something faster then a TreeSet to do so, as TreeSet sorts by definition.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
So you want them sorted? What about duplicates? Do they implement the Comparable interface, or can you implement a Comparator for your objects? You will need one or the other for a TreeSet.
What is the complexity of sorting a TreeSet? It should say in the documentation. Can you insert many instances in linear time, or logarithmic time? How does that compare with a List, and sorting it? Are your objects already in sorted order, or nearing sorted order? If your data are already sorted, a list might be better.

If you have answers to those questions, then TreeSet might be a good choice. It is easy enough to use, and simple in concept; you can write your own tree set in half an hour.
Yotam Ohayon
Greenhorn

Joined: Dec 31, 2010
Posts: 26
well
i went with TreeSet eventually
thanks!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Choosing the best data-sctructure for file storing