#ifndef DELTA_DRESS_H
#define DELTA_DRESS_H

#include "dress/dress.h"
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

// Compute the Δ^k-DRESS histogram of a graph.
//
// Enumerates all C(N, k) subsets of k vertices, removes each subset
// from the graph, runs DRESS on the resulting subgraph, and accumulates
// every converged edge value into a single histogram.
//
// The deletion subsets are generated by an iterative (stack-based) DFS
// over k-combinations, avoiding recursion.
//
// Parameters:
//   g          - input dress graph (used for topology only: N, E, U, V,
//                variant).  Not modified.
//   k          - deletion depth: number of vertices removed per subset.
//                k = 0 runs DRESS on the original graph (Δ^0).
//   iterations - maximum DRESS iterations per subgraph.
//   epsilon    - convergence tolerance for DRESS and histogram bin width.
//                The histogram has ceil(2 / epsilon) bins.
//   hist_size  - [out] if non-NULL, set to floor(2 / epsilon) + 1 on return.
//   keep_multisets - if non-zero, allocate and fill a flat matrix of
//                per-subgraph edge DRESS values.
//   multisets  - [out] on return, *multisets points to a heap-allocated
//                flat array of size C(N,k) * E.  Row r, edge e is at
//                (*multisets)[r * E + e].  Removed edges are NAN.
//                The caller must free(*multisets).  Ignored (and set to
//                NULL) when keep_multisets is 0.  May be NULL itself.
//   num_subgraphs - [out] if non-NULL, set to C(N,k) on return.
//
// Returns:
//   A heap-allocated int64_t array of length floor(2 / epsilon) + 1.
//   hist[i] counts the number of converged edge values falling in bin
//   i = floor(d / epsilon).  The top bin (index 2/epsilon) holds the
//   exact value 2.0.  The caller must free() the returned pointer.
//
// Complexity:
//   O( C(N,k) * iterations * E * d_max )
//   where d_max is the maximum degree.  Each subgraph is independent;
//   the outer loop is embarrassingly parallel (not parallelised here).
int64_t *delta_fit(p_dress_graph_t g, int k, int iterations,
                   double epsilon, int *hist_size,
                   int keep_multisets, double **multisets,
                   int64_t *num_subgraphs);

#ifdef __cplusplus
}
#endif

#endif // DELTA_DRESS_H
