• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Choosing the best data-sctructure for file storing

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 76873
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 76873
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well
i went with TreeSet eventually
thanks!
 
Campbell Ritchie
Marshal
Posts: 76873
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic