Post Reply 
50g: copy all stored objects to SD card individually
10-15-2016, 09:57 AM
Post: #4
RE: 50g: copy all stored objects to SD card individually
This may be look like a weird idea, but I'd approach this problem by simply not using the object's name directly as an SD file name. I've worked with version control systems often enough to know they usually don't do it either, so you could just use a VCS-inspired approach:
- The SD file name is built from the object's name via a hash function. You get a constant-length name (exact length depends on the function, of course) with a limited character set, usually 0-9 and a-f, so no more problems with too long names or illegal characters.
- Inside the file you store not just the object, but a list containing the object and its original name so you can restore it properly. Inside the file you don't have any char set issues, after all.

If you are worried about getting the same hash on different names, implement a collision handler.
You could use something like the ~1, ~2, ~3 suffixes on the SD file name to distinguish files with the same hash. Alternatively using the hash as a directory name containing files with that hash should work; inside the directory naming the files 1, 2, 3 etc should be enough. Then storing and recalling would need to loop through all files corresponding to the hash until the name that's stored inside matches. If there's no match, storing creates a new file, and recalling errors out.

For starters Java's string hashing function should work fine: start with 0, then for each character: multiply with 31, add character value, repeat.

The best part: In theory UserRPL can do it. It might be slow though.
Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: 50g: copy all stored objects to SD card individually - 3298 - 10-15-2016 09:57 AM

User(s) browsing this thread: 1 Guest(s)