Mapping AppendTo over the list of items to append escapes the copy inefficiency.
a = Range[5];
AppendTo[a, #] & /@ Range[6, 10];
a
(* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} *)
Update with function
ClearAll[joinTo]
Attributes[joinTo] = {HoldFirst};
joinTo[s_Symbol, items_List] := Last@(AppendTo[s, #] & /@ items)
joinTo[a,Range[11,15]]
(* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} *)
Hope this helps.
Update 2: Benchmarks
With joinTo in this post:
a = Range[10000];
joinTo[a, Range[10000]] // AbsoluteTiming // First
(* 0.837118 *)
With JoinTo (the OP's version):
ClearAll[JoinTo];
SetAttributes[JoinTo, HoldFirst];
JoinTo[a_, b_List] := (a = Join[a, b];)
b = Range[10000];
JoinTo[b, Range[10000]] // AbsoluteTiming // First
(* 0.000032 *)
To check if the codes are doing the same thing:
a == b
(* True *)
List, as ina={a,b}or maybe use ofReap[...Sow[a]...], depending on what is the application at hand. – Daniel Lichtblau Jan 02 '16 at 23:56Join[a,b]were known so that values had just to be updated instead of inserted)?AssociateToat least claims to offer efficient in place modification. – Sascha Jan 03 '16 at 00:01AssociateTooperations are done, and there may be an ordering issue (I think new things get added at the back and not the front). I'm not sure what algorithmic complexity to expect for adding new items; might be O(log n) for n=length of the association (which of course is much better than O(n)). Best I can suggest is that this approach be tried and timed. – Daniel Lichtblau Jan 03 '16 at 16:32AssociateToto add key-value pairs and compare with list operations. – Sascha Jan 03 '16 at 16:42Internal\Bagand friends. The latter are employed bySowandReap`. By the way, it would be helpful if you could state clearly in what respects you would like your idea to be improved upon. – Oleksandr R. Feb 02 '16 at 23:14