VList: Difference between revisions

Content added Content deleted
(J: bugfix and a caution)
m (→‎{{header|J}}: I thought I had adequately proofread that text...)
Line 1,062: Line 1,062:
Caution: this is an accurate model of the vlist data structure but should not be used if performance is critical.
Caution: this is an accurate model of the vlist data structure but should not be used if performance is critical.


If performance is critical use J's native operations and make sure that there's only the named reference to the list when adding or removing the last item from the list. For example, given <code>L=:100 200 303 404</code>, use <code>L=: L,555</code> to append to the list, and and after using <code>{:L</code> to extract the final element from L, use <code>L=: }:L</code> to discard the final element from the list. (And, of course, <code>#L</code> will report the size of the list.) J's implementation uses techniques which are in some ways similar in character to vlists for these operations (but uses copy on write if the there's other references to the list).
If performance is critical use J's native operations and make sure that there's only the named reference to the list when adding or removing the last item from the list. For example, given <code>L=:100 200 303 404</code>, use <code>L=: L,555</code> to append to the list, and and after using <code>{:L</code> to extract the final element from L, use <code>L=: }:L</code> to discard the final element from the list. (And, of course, <code>#L</code> will report the size of the list.) J's implementation uses techniques which are in some ways similar in character to vlists for these operations (but uses copy on write if there's other references to the list).


=={{header|Kotlin}}==
=={{header|Kotlin}}==