Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Choosing the best data-sctructure for file storing

 
Yotam Ohayon
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48976
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48976
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well
i went with TreeSet eventually
thanks!
 
Campbell Ritchie
Sheriff
Pie
Posts: 48976
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic