Skip to main content
added 200 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269

You shouldcan use Sow for this in conjunction with CheckAbort:

Reap@CheckAbort[Sow[...], ...]

You can read more about this here

Other than that there is bags. It will be as fast as Sow since Sow is implemented in terms of bags, but you will not lose the content of the bag if you interrupt the computation.

Quick recap:

bag = Internal`Bag[{}] (* Create an empty bag *)
Internal`StuffBag[bag, value] (* Add a value to the bag *)
Internal`BagLength[bag] (* The number of values in the bag *)
Internal`BagPart[bag, part] (* Retrieve values from bag *)

Another option is to use linked lists.

You should use bags. It will be as fast as Sow since Sow is implemented in terms of bags, but you will not lose the content of the bag if you interrupt the computation.

Quick recap:

bag = Internal`Bag[{}] (* Create an empty bag *)
Internal`StuffBag[bag, value] (* Add a value to the bag *)
Internal`BagLength[bag] (* The number of values in the bag *)
Internal`BagPart[bag, part] (* Retrieve values from bag *)

Another option is to use linked lists.

You can use Sow for this in conjunction with CheckAbort:

Reap@CheckAbort[Sow[...], ...]

You can read more about this here

Other than that there is bags. It will be as fast as Sow since Sow is implemented in terms of bags, but you will not lose the content of the bag if you interrupt the computation.

Quick recap:

bag = Internal`Bag[{}] (* Create an empty bag *)
Internal`StuffBag[bag, value] (* Add a value to the bag *)
Internal`BagLength[bag] (* The number of values in the bag *)
Internal`BagPart[bag, part] (* Retrieve values from bag *)

Another option is to use linked lists.

added 283 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269

You should use bags. It will be as fast as Sow since Sow is implemented in terms of bags, but you will not lose the content of the bag if you interrupt the computation.

Quick recap:

bag = Internal`Bag[{}] (* Create an empty bag *)
Internal`StuffBag[bag, value] (* Add a value to the bag *)
Internal`BagLength[bag] (* The number of values in the bag *)
Internal`BagPart[bag, part] (* Retrieve values from bag *)

Another option is to use linked lists.

You should use bags. It will be as fast as Sow since Sow is implemented in terms of bags, but you will not lose the content of the bag if you interrupt the computation.

You should use bags. It will be as fast as Sow since Sow is implemented in terms of bags, but you will not lose the content of the bag if you interrupt the computation.

Quick recap:

bag = Internal`Bag[{}] (* Create an empty bag *)
Internal`StuffBag[bag, value] (* Add a value to the bag *)
Internal`BagLength[bag] (* The number of values in the bag *)
Internal`BagPart[bag, part] (* Retrieve values from bag *)

Another option is to use linked lists.

Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269

You should use bags. It will be as fast as Sow since Sow is implemented in terms of bags, but you will not lose the content of the bag if you interrupt the computation.