pub fn extract_source(
language: Language,
source: &[u8],
config: &Config,
) -> Result<Vec<FunctionFeatures>, Error>Expand description
Extracts the features of every function in source.
Every function, method, constructor, lambda or block of the language is a
function unit, nested ones included. Functions with syntax errors are skipped.
Fingerprints, MinHash signatures and LSH buckets are computed only for
functions with at least Config::min_tokens tokens.
§Errors
Error::InvalidConfig when config is invalid, and Error::Parse when
the source cannot be parsed at all.
§Examples
Renaming identifiers changes the N0 hash but not the N1 hash:
use pelicode_core::{Config, Language, Level, extract_source};
let a = extract_source(Language::Java, b"class A { int twice(int x) { return x * 2; } }", &Config::default()).unwrap();
let b = extract_source(Language::Java, b"class B { int doubled(int v) { return v * 2; } }", &Config::default()).unwrap();
assert_eq!(a[0].name, "twice");
assert_ne!(a[0].exact_hashes[&Level::N0], b[0].exact_hashes[&Level::N0]);
assert_eq!(a[0].exact_hashes[&Level::N1], b[0].exact_hashes[&Level::N1]);