2
Ich habe Schwierigkeiten, einen Algorithmus zu schreiben, der ein Array aus einem Array von Arrays an Ort und Stelle liest, ohne ein temporäres Array zu erstellen.Array von beliebiger Länge aus einem Array von Arrays lesen
Hier ist meine Idee:
[data correspond to a byte[][] that contains the data we want to read from]
[each arrays can be of arbitrary sizes. No assumption can be done there]
[limit is the sum of bytes that has been wrote to data beforehand. (Appending an array of size X increment limit by X - 1)]
[position is the current position that has been read by previous calls to read(...)]
1) Skip until array that belongs to position is reached
2) Copy from saved position in the array to the output array
3) Move to next array
4) Copy as much bytes as we can into the output buffer
5) Repeat 3-4 until output buffer is filled with the proper amount of data or we've reached the end of the data.
Ein Beispiel (pos = 12, Länge = 16):
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ] // Skip this row as pos > row.length
[ ][ ][X][X][X][X][X] // Read from position 2 (row.length - relative pos) until end of array
[X][X][X][X][X][X][X][X] // Read entire array as length left > row.length
[X][X][X][ ][ ][ ][ ][ ][ ] // Read from 0 to length left (aka 3)
[ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
Vielen Dank für jede Hilfe!
* "Es scheint, es funktioniert nicht" * können Sie sich mehr auf das erklären? Was ist los? – 4castle
Ich meine, wenn ich die Methode ausführen, gebe ich nicht die richtige Reihenfolge aus. Aber ich habe darüber nachgedacht, ich denke, ich versaue auf der srcOffset & Position Da Zeiger nicht bewegen, gibt Position - Zeiger den falschen Wert. – Romain