1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 SAF_AltIndexSpec *
 saf_declare_alternate_indexspec(SAF_ParMode pmode,              /*The parallel mode*/
                                 SAF_Db *db,                     /* Database to contain the new index spec. */
                                 SAF_Set *containing_set,        /* The containing set of the collection.*/
                                 SAF_Cat *cat,                   /* The collection category. */
                                 const char *name,               /* The name you wish to assign to this alt index spec*/
                                 hid_t data_type,                /* The data type used to identify members of the collection*/
                                 hbool_t is_explicit,            /* Whether the indexing specification is explicit or implicit*/
                                 SAF_IndexSpec implicit_ispec,   /* The alternate indexing scheme of the collection. Ignored
                                                                  * for explicit specs. Pass SAF_NA_INDEXSPEC for explicit
                                                                  * alternative index specs. */
                                 hbool_t is_compact,             /* Whether the indexing specification is compact or not.
                                                                  * Ignored for implicit specs. */
                                 hbool_t is_sorted,              /* Whether the indexing specification is sorted or not.
                                                                  * Ignored for implicit specs. */
                                 SAF_AltIndexSpec *aspec         /* [OUT] The optional returned alternate index spec handle. If
                                                                  * the null pointer is passed for this argument then new
                                                                  * memory is allocated and returned, otherwise this argument
                                                                  * serves as the successful return value. */
                                 )
 {
     SAF_ENTER(saf_declare_alternate_indexspec, NULL);
     ss_collection_t             coll;
     ss_indexspec_t              defaultidx;
     ss_indexspecobj_t           *init=NULL;
     ss_scope_t                  scope=SS_SCOPE_NULL;    /* Scope in which to create new index spec. */
     size_t                      i;

     SAF_REQUIRE(_saf_valid_pmode(pmode), SAF_LOW_CHK_COST, NULL,
                 _saf_errmsg("PMODE must be valid"));
     if (!_saf_is_participating_proc(pmode)) SAF_RETURN(NULL);

     SAF_REQUIRE(SS_SET(containing_set),SAF_LOW_CHK_COST, NULL,
                 _saf_errmsg("CONTAINING_SET must be a valid set handle"));
     SAF_REQUIRE(SS_CAT(cat), SAF_LOW_CHK_COST, NULL,
                 _saf_errmsg("CAT must be a valid cat handle"));

     /* The scope in which to declare the new indexspec */
     ss_file_topscope(db, &scope);

     if (SS_CAT(cat)) {
         /* Confirm the containing set has the category defined on it. */
         if (NULL==_saf_getCollection_set(containing_set, cat, &coll))
             SAF_ERROR(NULL, _saf_errmsg("set \"%s\" does not have a collection of category \"%s\"",
                                         ss_string_ptr(SS_SET_P(containing_set,name)),
                                         ss_string_ptr(SS_CAT_P(cat,name))));

         /* Obtain the default indexing scheme. */
         if (NULL==ss_array_get(SS_COLLECTION_P(&coll,indexing), ss_pers_tm, (size_t)0, (size_t)1, &defaultidx) ||
             !SS_INDEXSPEC(&defaultidx))
             SAF_ERROR(NULL, _saf_errmsg("unable to obtain default indexing specification for set \"%s\"",
                                         ss_string_ptr(SS_SET_P(containing_set,name))));
     }

     /* Fill in an index spec record */
     init = is_explicit ? SS_INDEXSPEC(&defaultidx) : NULL;
     aspec = (ss_indexspec_t*)ss_pers_new(&scope, SS_MAGIC(ss_indexspec_t), (ss_persobj_t*)init, SAF_ALL==pmode?SS_ALLSAME:0U,
                                          (ss_pers_t*)aspec, NULL);
     if (!aspec)
         SAF_ERROR(NULL, _saf_errmsg("unable to initialize index spec record"));
     if (SAF_EACH==pmode) SS_PERS_UNIQUE(aspec);
     if (!is_explicit){
         /* It is an implicit alt indexing scheme; use the IMPLICIT_ISPEC */
         SS_INDEXSPEC(aspec)->ndims = implicit_ispec.ndims;
         for (i=0; i<SAF_MAX_NDIMS; i++){
             SS_INDEXSPEC(aspec)->sizes[i] = implicit_ispec.sizes[i];
             SS_INDEXSPEC(aspec)->origins[i] = implicit_ispec.origins[i];
             SS_INDEXSPEC(aspec)->order[i]   = implicit_ispec.order[i];
         }
         SS_INDEXSPEC(aspec)->index_type  = SS_INDEXSPEC(&defaultidx)->index_type; /*implicit_ispec.index_type; does not exist*/
     }
     ss_string_set(SS_INDEXSPEC_P(aspec,name), name);
     SS_INDEXSPEC(aspec)->coll = coll;
     SS_INDEXSPEC(aspec)->is_explicit = is_explicit;
     SS_INDEXSPEC(aspec)->is_sorted = is_sorted;
     SS_INDEXSPEC(aspec)->is_compact = is_compact;

     /* This new index spec should be added to the end of the array of index specs. */
     i = ss_array_nelmts(SS_COLLECTION_P(&coll,indexing));
     ss_array_resize(SS_COLLECTION_P(&coll,indexing), i+1);
     ss_array_put(SS_COLLECTION_P(&coll,indexing), ss_pers_tm, i, (size_t)1, aspec);

     /* Save the datatype */
     SS_INDEXSPEC(aspec)->m.data_type = data_type;
     SAF_LEAVE(aspec);
 }