From e0c5e4082689e6e49d80c574f35b9e401b7fc83a Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 3 Apr 2017 15:57:27 +0100 Subject: Add a cheap OrderedSet implementation This just makes an OrderedDict look more like a set class. This results in neater code than if we use OrderedDict to hold sets directly. There is a "real" OrderedSet implementation available here, but it lacks a clear license: https://code.activestate.com/recipes/576694/ --- mesonbuild/mesonlib.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'mesonbuild') diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index c7368d5..f0bf9ee 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -16,6 +16,7 @@ import stat import platform, subprocess, operator, os, shutil, re +import collections from glob import glob @@ -672,3 +673,18 @@ def get_filenames_templates_dict(inputs, outputs): if values['@OUTDIR@'] == '': values['@OUTDIR@'] = '.' return values + +class OrderedSet(collections.OrderedDict): + ''' + A 'set' equivalent that preserves the order in which items are added. + + This is a hack implementation that wraps OrderedDict. It may not be the + most efficient solution and might need fixing to override more methods. + ''' + def __init__(self, iterable=None): + if iterable: + self.update(iterable) + + def update(self, iterable): + for item in iterable: + self[item] = True -- cgit v1.1