// Copyright (C) 2025  The Software Heritage developers
// See the AUTHORS file at the top-level directory of this distribution
// License: GNU General Public License version 3, or any later version
// See top-level LICENSE file for more information

use std::path::PathBuf;

use anyhow::Result;
use clap::Parser;
use dsi_bitstream::prelude::BE;
use mimalloc::MiMalloc;
use webgraph_cli::build::ef::{CliArgs, build_elias_fano};

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

#[derive(Parser, Debug)]
#[command()]
/// Add a .ef file next to a .graph file,
/// which allows fast random access to it.
struct Args {
    #[clap(flatten)]
    webgraph_args: webgraph_cli::GlobalArgs,
    #[arg(long)]
    /// Where to read the .graph file, and write its .ef index -- without the extensions
    graph: PathBuf,
}

pub fn main() -> Result<()> {
    let args = Args::parse();

    tracing_subscriber::fmt()
        .with_env_filter(
            tracing_subscriber::EnvFilter::from_default_env()
                .add_directive(tracing::Level::INFO.into()),
        )
        .init();

    build_elias_fano::<BE>(
        // endianness of the .offsets file, which is always BE even if the
        // .graph is LE.
        args.webgraph_args,
        CliArgs {
            basename: args.graph,
            number_of_nodes: None,
        },
    )
}
