Stirling numbers of the first kind: Difference between revisions
m
Simplified code
m (Phix/mpfr) |
m (Simplified code) |
||
Line 133:
typedef struct stirling_cache_tag {
int
int* values;
} stirling_cache;
if (k == 0)▼
int* values = calloc(n * (n + 1)/2, sizeof(int));▼
return n == 0 ? 1 : 0;▼
if (n > sc->max || k > n)▼
return 0;▼
}▼
if (values == NULL)
return false;
sc->
sc->values = values;
for (int n = 1; n <= max; ++n) {
for (int k = 1; k <= n; ++k) {
int s1 = stirling_number1(sc, n - 1, k - 1);▼
int s2 = stirling_number1(sc, n - 1, k);▼
}▼
}▼
return true;
}
Line 149 ⟶ 164:
free(sc->values);
sc->values = NULL;
▲}
▲int* stirling_cache_get(stirling_cache* sc, int n, int k) {
▲ return (n > sc->n) ? NULL : &sc->values[n*(n-1)/2 + k - 1];
▲ if (k == 0)
▲ return n == 0 ? 1 : 0;
▲ if (k > n)
▲ return 0;
▲ }
▲ int s1 = stirling_number1(sc, n - 1, k - 1);
▲ int s2 = stirling_number1(sc, n - 1, k);
▲ *value = 1 + s1 + s2 * (n - 1);
▲ }
}
|