Skip to content
Snippets Groups Projects
  • Jonathan Schöbel's avatar
    875cd8a3
    Validator: add initializer · 875cd8a3
    Jonathan Schöbel authored
    There is a method to add a set of tags to a validator on initialisation.
    First this removes a user application from the burden of maintaining the
    html spec and also is more performant, as a lot of tags are to be
    inserted at once, so there aren't multiple allocation calls.
    As the validator needs the tags to be in order, the tags must be sorted
    on insertion. Of course it would be easier for the code, if the tags
    were already in order, but first there could be easily a mistake and
    second sorting the tags by an algorithm allows the tags to be specified
    in a logically grouped and those more maintainable order.
    For the sorting, insertion sort is used. Of course it has a worse
    quadratic time complexity, but in a constructor, I wouldn't introduce
    the overhead of memory managment a heap- or mergesort would introduce
    and in-place sorting is also out, because the data lies in ro-memory.
    Thus I choose an algorithm with constant space complexity. Also the
    'long' running time is not so important, as the initilization only runs
    at startup once and the tags are not likely to exceed a few hundred so
    even a quadratic time isn't that bad.
    875cd8a3
    History
    Validator: add initializer
    Jonathan Schöbel authored
    There is a method to add a set of tags to a validator on initialisation.
    First this removes a user application from the burden of maintaining the
    html spec and also is more performant, as a lot of tags are to be
    inserted at once, so there aren't multiple allocation calls.
    As the validator needs the tags to be in order, the tags must be sorted
    on insertion. Of course it would be easier for the code, if the tags
    were already in order, but first there could be easily a mistake and
    second sorting the tags by an algorithm allows the tags to be specified
    in a logically grouped and those more maintainable order.
    For the sorting, insertion sort is used. Of course it has a worse
    quadratic time complexity, but in a constructor, I wouldn't introduce
    the overhead of memory managment a heap- or mergesort would introduce
    and in-place sorting is also out, because the data lies in ro-memory.
    Thus I choose an algorithm with constant space complexity. Also the
    'long' running time is not so important, as the initilization only runs
    at startup once and the tags are not likely to exceed a few hundred so
    even a quadratic time isn't that bad.