1. Limit line length. Then offset is ( line* length ).
2. Name your relation.
3. Hijack the operating system. Remember:
on disk looks like
abc\ndef
looks like
abcd\ndef
So, if you want line 2, you have to scan line 1.- Hide quoted text -
You also have
f.seek( X )
f.write( 'abc' )
which writes 'abc' in the middle, at offset X.
f.seek( 0, SEEK_END )
takes you to the back, and don't forget
f.flush( ).
Say you have:
File:
abc
def
ghi
Symbols:
0-3
1-3
2-3
abcdefghi
and you want to make abc abC. Then
f.seek( 2 )
f.write( 'C' )
does work.
If you want to make abc ab, then you change a different file
table.seek( 0 )
table.write( chr( 2 ) )
( or bytes( [ 2 ] ) in 3.0 ).
If you want to make abc abcd, then you change both.
f.seek( 9 )
f.write( 'd' )
table.seek( 0 )
table.write( chr( 4 ) )
But. Now you have item 0 in two places. 'abc' somewhere and 'd'
somewhere else, at 0 and at 9 respectively. I think the file system
overallocates room for String 1. You would read:
0- 2- [ 3, 1 ]
for 'abc'+'d'
and
1- 1- [ 3 ]
2- 1- [ 3 ]
for 'def' and 'ghi', where actual representations would be:
0- 2- [ 0/3, 9/1, 0, 0, 0, 0, 0, 0 ]
1- 1- [ 3/3, 0, 0, 0, 0, 0, 0, 0 ]
2- 1- [ 6/3, 0, 0, 0, 0, 0, 0, 0 ]
As your chains start to grow, leave table 8xN, and just copy strings
to new sectors when they become long:
0- 1- [ 9/4, 0, 0, 0, 0, 0, 0, 0 ]
1- 1- [ 3/3, 0, 0, 0, 0, 0, 0, 0 ]
2- 1- [ 6/3, 0, 0, 0, 0, 0, 0, 0 ]
You can insort in linear time when you're looking for available slots.
'jklm' can't fit at 0.
0- 1- [ 9/4, 0, 0, 0, 0, 0, 0, 0 ]
1- 1- [ 3/3, 0, 0, 0, 0, 0, 0, 0 ]
2- 1- [ 6/3, 0, 0, 0, 0, 0, 0, 0 ]
3- 1- [ 13/4, 0, 0, 0, 0, 0, 0, 0 ]
but 'nop' can.
0- 1- [ 9/4, 0, 0, 0, 0, 0, 0, 0 ]
1- 1- [ 3/3, 0, 0, 0, 0, 0, 0, 0 ]
2- 1- [ 6/3, 0, 0, 0, 0, 0, 0, 0 ]
3- 1- [ 13/4, 0, 0, 0, 0, 0, 0, 0 ]
4- 1- [ 0/3, 0, 0, 0, 0, 0, 0, 0 ]
'jklm' could've with a split:
0- 1- [ 9/4, 0, 0, 0, 0, 0, 0, 0 ]
1- 1- [ 3/3, 0, 0, 0, 0, 0, 0, 0 ]
2- 1- [ 6/3, 0, 0, 0, 0, 0, 0, 0 ]
3- 2- [ 0/3, 13/1, 0, 0, 0, 0, 0, 0 ]
and with 'nop':
0- 1- [ 9/4, 0, 0, 0, 0, 0, 0, 0 ]
1- 1- [ 3/3, 0, 0, 0, 0, 0, 0, 0 ]
2- 1- [ 6/3, 0, 0, 0, 0, 0, 0, 0 ]
3- 2- [ 0/3, 13/1, 0, 0, 0, 0, 0, 0 ]
4- 1- [ 14/3, 0, 0, 0, 0, 0, 0, 0 ]
There's an easy chance you can beat DbfilenameShelf for your
application.- Hide quoted text -
- Show quoted text -