July 08, 2006 Set and Ranges template. | ||||
---|---|---|---|---|

| ||||

Ddoc documentation: http://peylow.no-ip.org/~peylow/set.html Actual implementation: http://peylow.no-ip.org/~peylow/set.d I whipped up a module with templates for Ranges and Sets. Ranges are only useful for numerical values. Sets can be used for any value; a set of {1, 2, 3} is just as valid as a set of {green, whale, 42}. Currently only empty and finite ranges are supported (Infinite set if you make a range over real numbers), infinite and non continuous ranges would be nice, but that is a task for another day. Unions, intersection, complements, membership test and iterations can naturally be done on sets. As well as construction a set from a range non continuous range. Empty, finite, and infinite sets are supported. Unions, intersections, unary and binary complements, membership tests, and iterations over set members supported. Three classes are used in combination to allow for full naive set algebra; Set - For finite sets. FunctionSet - An infinite set with members defined by function. CombiningSet - An infinite set construction by combining sets. The optimal set class is constructed for each operation (union, intersection, etc). Maybe CombinedSet should be named ComputedSet? Three global sets provided; evenIntSet - A set of all even integers. oddIntSet - A set of all odd integers. primeIntSet - A set of all primes. Comments, and bug hunt requested :) // Fredrik |

July 08, 2006 Re: Set and Ranges template. | ||||
---|---|---|---|---|

| ||||

Posted in reply to Fredrik Olsson | Small additional comments: Is it a bug in GDC or am I using Templates wrong? When putting the templates in a separate module I get linking errors when compiling with template instantiations not originally used by the imported module. For example: /usr/bin/ld: Undefined symbols: __init_35TypeInfo_C4toys3set10__T3SetTfZ3Set __init_39TypeInfo_C4toys3set12__T5RangeTfZ5Range __init_53TypeInfo_C4toys3set19__T11AbstractSetTfZ11AbstractSet Also i need to make "static if"s on numerical (any real or integer type) and on integers (Only integer but all types). How do I do this in an easy way? // Fredrik |

Copyright © 1999-2016 by the D Language Foundation