add O(log(n)) c impl