import yaml
import collections
import codecs


def load_yaml(filename):
    """
    load yaml file and return dict, order in the file is reserved

    :param filename: input filename
    """
    yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
                         lambda loader, node: collections.OrderedDict(loader.construct_pairs(node)))

    vdict = collections.OrderedDict()
    with codecs.open(filename, "r", "utf-8") as f:
        vdict = yaml.load(f, Loader=yaml.SafeLoader)
    return vdict