# -*- coding: utf-8 -*-
#
# Copyright 2012-2015 Spotify AB
# Modifications copyright (C) 2018 databand.ai
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


def get_editdistance(a, b):
    """ Simple unweighted Levenshtein distance """
    r0 = range(0, len(b) + 1)
    r1 = [0] * (len(b) + 1)

    for i in range(0, len(a)):
        r1[0] = i + 1

        for j in range(0, len(b)):
            c = 0 if a[i] is b[j] else 1
            r1[j + 1] = min(r1[j] + 1, r0[j + 1] + 1, r0[j] + c)

        r0 = r1[:]

    return r1[len(b)]
