/
telnov.ob
/
postgresql-patterns-library
Обзор
Документация
Войти
/
telnov.ob
/
postgresql-patterns-library
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
functions/entropy_redundancy.sql
37 строк
1 KB
rin-nas
language sql RETURN expression
14 апр 2026, 13:54
14 апр 2026, 13:54
cfbed9d
Код
Авторство
О чём код?
create or replace function public.entropy_redundancy(s text) returns numeric immutable strict -- returns null if any parameter is null parallel safe security invoker language sql set search_path = '' return log(2, char_length(entropy_redundancy.s)) - public.entropy(entropy_redundancy.s); comment on function public.entropy_redundancy(s text) is 'Returns text redundancy > 0'; create or replace function public.entropy_redundancy(data bytea) returns numeric immutable strict -- returns null if any parameter is null parallel safe security invoker language sql set search_path = '' return log(2, octet_length(entropy_redundancy.data)) - public.entropy(entropy_redundancy.data); comment on function public.entropy_redundancy(s text) is 'Returns data redundancy > 0. For compressed data the value tends to 0'; -- TEST do $$ begin assert round(public.entropy_redundancy('abracadabra'), 2) = 1.42; assert round(public.entropy_redundancy('абракадабра'), 2) = 1.42; assert round(public.entropy_redundancy('абракадабра'::bytea), 2) = 2.1; assert round(public.entropy_redundancy('\x11D481C8E032988E9763FD2780'::bytea), 2) = 0; end; $$;