need an Set of Set of Set in Java ... any altenatives?

  • 0
    @torbuntu have a folder structure that is three leveled, and every level has folder names or file names, that are numbers ...


    1111 / 1000 / 76732 <-- the last one is a file

    and most importantly, i want to CACHE the file access, because it is so slow
  • 5
    If you need to access the same file a lot of times why not a hash map where the path is its key?
  • 2
    Alternatives to Java or what?
  • 0
    @orhun alternatives to set of set of set
  • 0
    @jennytengsonM .. i am not sure, the issue is, that this has to be threadsafe also, ... i am just thinking if i could use the whole path as key, ... i think that should be possible, let me check that one minute (need 5 minutes at least)
  • 0
    @24th-Dragon could be possible, i need to check it right now, if i have all properties in the given context, to acuire the whole path at once
  • 0
    @jennytengsonM ... i do have the whole path, so i could save that as a key, but i need to store two other things related to this path, ... the last access timestamp and the files that are in that folder .... hmm ...
  • 0
    @24th-Dragon ... i do have the path in the context, but i need to store the last-access-timestamp (filesystem access needs to be restricted to 1 acess within 3 seconds) and the files that are in that folder need also to be stored, i could theoretically create two thread-safe collections, but at least one needs to have another collection as value ..... e.g. k: <path> v: <last-access-date> and the other collection: k: <path> v: list-of<files>
  • 1
    A Wheel. But in octagon shape...

    Two options: use the file system directly, or... Use Some sort of a +- tree structure.
  • 0
    @magicMirror ... i had the same in mind, i am reading currently some articles about treemap and treeset, couldnt figure out how they work, any good articles with images that you know of ?
  • 1
    If you have to implement it yourself, how about a set of file or folder where folder is a set of file or folder recursively?
  • 0
    @tekashi the issue is, that the whole thing is somehow abstracted, so i do not have / or even want to access it on file level or folder level, i just want to cache the access dates to the given paths, so that i do not call a method which is accessing the file system ... in my opinion i would change this base module and write it from scratch, but the issue is it is so huge, that any changes would require months of work, to make it work as it is right now ...
  • 1
    How about just ignoring the number 3 and making it an n?

    Build the recursive structure now.
  • 0
    I may be completely off, but why not create a class called X with some fields like "lastAccessDate", "path", "listOfX" and maybe "isFile" or something. That way you get all the info you need and you will only use one collection or map or whatever.
  • 1
    @shakur tree map :

    Instead of a hash map, you use a binary tree to store the data. Your key type need a comparison method to make it work.
    It works as follow :
    On insert, you compare the root node with the key to insert. If bigger, you add the value on the right. If lower on the left. If there is a node already, you compare recursively until you find an empty spot.
    Reading goes the same way : compare node with key. If equal: return value. If different: recursion left or right. If empty, return null.

    There are probably some optimizations but that is the basic idea.
  • 0
    @UltimateZero thank you for your support, i solved that issue by sychronized collections, and bypassed it beforehand with using an "1 second caching check"
  • 0
    @react-guy thank you for your solution, this is a good way to achieve fast accessible big structures, i will note it down
Add Comment