"""
Sketchnu has Numba implementations of sketch algorithms and other useful functions 
that utilize hash functions.

Copyright (C) 2022 Matthew Hendrey

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
"""
import numpy as np


def zipf(vocab_size, s: int = 1):
    denom = 0.0
    for i in range(vocab_size):
        denom += 1 / (i + 1) ** s

    p = np.zeros(vocab_size, np.float64)
    for k in range(1, vocab_size + 1):
        p[k - 1] = 1 / k ** s / denom

    return p / p.sum()
