void *threadAlgo(void *threadid) { int tid; tid = (int) threadid; list *Rs=Nullptr(list); list2_get_list(&Rs,Ri,tid); list *Ss=Nullptr(list); list2_get_list(&Ss,Si,tid); printf("%d -> Ri : ",tid); list_affiche(Rs); printf("%d -> Si : ",tid); list_affiche(Ss); list *inter=Nullptr(list); list_intersection(&inter,Rs,Ss); printf("%d -> Ti : ",tid); list_affiche(inter); pthread_exit(inter); }
void test_concat_append_add_union_intersection_difference(void) { List list1 = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE); list_sort_by_item(&list1); list_unique(&list1); printf("Original List 1 ::: "); list_print(&list1); List list2 = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE); list_sort_by_item(&list2); list_unique(&list2); printf("%sOriginal List 2 ::: ", brown); list_print(&list2); List concat = list_concat(&list1, &list2); printf("%sConcatenation List ::: ", cyan); list_print(&concat); List append = list_duplicate(&list1); list_append(&append, &list2); printf("%sList 1 appended to list 2 ::: ", magenta); list_print(&append); List add = list_duplicate(&list1); list_add(&add, &list2); printf("%sList 1 added to list 2 ::: ", green); list_print(&add); List union_list = list_union(&list1, &list2); printf("%sList Union ::: ", blue); list_print(&union_list); List intersection_list = list_intersection(&list1, &list2); printf("%sList Intersection ::: ", red); list_print(&intersection_list); List difference_list = list_difference(&list1, &list2); printf("%sDifference List ::: ", cyan); list_print(&difference_list); uint union_size = list_union_size(&list1, &list2); printf("%sList Union Size = %d\n", brown, union_size); uint intersection_size = list_intersection_size(&list1, &list2); printf("%sList Intersection Size = %d\n", black, intersection_size); uint difference_size = list_difference_size(&list1, &list2); printf("%sList Difference Size = %d\n", black, difference_size); printf("%s",none); }
void propogate_registration( SAState *psa, const char* lang, const char* srvtype, const char* url, const char* scopeList, const char* attrlist, int life ) { int i, needToCheckDAList=0; SLPInternalError err = SLP_OK; DATable* pdat = GetGlobalDATable(); const char* pcSL = GetEncodedScopeToRegisterIn(); if ( !psa || !pdat ) return; if ( scopeList && scopeList[0] != '\0' ) pcSL = scopeList; LockGlobalDATable(); for (i = 0; i < pdat->iSize; i++) { if ( list_intersection(pdat->pDAE[i].pcScopeList, pcSL ) ) { if ( pdat->pDAE[i].iStrikes <= kNumberOfStrikesAllowed ) { err = propogate_registration_with_DA(psa,pdat->pDAE[i].sin, lang, url, srvtype, pcSL, attrlist, life); if ( err ) { #ifdef ENABLE_SLP_LOGGING SLP_LOG( SLP_LOG_DA, "Error trying to propogate a registration to DA: %s", inet_ntoa(pdat->pDAE[i].sin.sin_addr) ); // just log this #endif pdat->pDAE[i].iStrikes++; // and give em a strike. needToCheckDAList = 1; // look for any DAs that should be struck out } } } #ifdef ENABLE_SLP_LOGGING else { SLP_LOG( SLP_LOG_DEBUG, "Skipping registration propigation with DA: %s, DA ScopeList: %s, service ScopeList: %s", inet_ntoa(pdat->pDAE[i].sin.sin_addr), pdat->pDAE[i].pcScopeList, pcSL ); } if ( err ) { SLP_LOG( SLP_LOG_DA, "Error trying to propogate a registration to DA: %s", inet_ntoa(pdat->pDAE[i].sin.sin_addr) ); // just log this } #endif } UnlockGlobalDATable(); if ( needToCheckDAList ) dat_boot_off_struck_out_das(); }
EXPORT SLPInternalError dat_get_da(const DATable *ignore, const char *pcScopeList, struct sockaddr_in *psin) { int i, found = 0; DATable* pdat = GetGlobalDATable(); // ignore what they pass in, only reference the globaly defined table SLPInternalError error = SLP_OK; if (!pdat || !pcScopeList || !psin) return SLP_PARAMETER_BAD; LockGlobalDATable(); psin->sin_addr.s_addr = 0L; /* Testing mode! Return no DA if this property is set */ if (SLPGetProperty("com.sun.slp.noDA") && !SDstrcasecmp(SLPGetProperty("com.sun.slp.noDA"),"true")) { error = SLP_OK; } else { for (i = 0; i < pdat->iSize; i++) { if (list_intersection(pcScopeList,pdat->pDAE[i].pcScopeList)) { *psin = pdat->pDAE[i].sin; found = 1; break; } } if ( pdat->iSize && !found ) { // we have DA's discovered but no nothing about the scope they are asking for... error = SLP_SCOPE_NOT_SUPPORTED; } } UnlockGlobalDATable(); return error; }
/* * list_subset * * Compares two lists. All the elements in the first list must be * in the second and neither may be empty lists. * * pcSub The list which must have all elements in pcSuper * pcSuper The list which must contain all or more elements than in pcSub * * Returns: * 0 if not a subset, 1 if it is a subset. * * Side effects: * None. */ EXPORT int list_subset(const char *pcSub, const char *pcSuper) { int offset = 0; char c, *pcScope; if (!pcSub || !pcSuper || /* either are NULL */ (pcSub[0] == '\0' && pcSuper[0] != '\0')) { /* sub empty, super not */ return 0; } while((pcScope = get_next_string(",",pcSub,&offset,&c))) { if (!list_intersection(pcScope,pcSuper)) { SLPFree(pcScope); return 0; } SLPFree(pcScope); } return 1; }
int main() { list_t a = make_ascending_list(5); insert('z', header(a)); list_t b = make_ascending_list(12); traversal(print_node, a); sep; traversal(print_node, b); sep; list_t u = list_union(a, b); traversal(print_node, u); sep; list_t i = list_intersection(a, b); traversal(print_node, i); destory(a); destory(b); destory(u); destory(i); return 0; }
/* * list_merge * * This function will build a list of unique elements. It assumes * that the items arriving with pcNewList are packed, for efficiency. * If the list grows too large, it will be grown to take in the new * string and 'breathing room' for further expansion. * * pcNewList The new list to merge in with the old one. * ppcList A pointer to the buffer with the list to be built onto. * piListLen The max size of the list list to be build onto. * iCheck If this is 0, don't check for duplicates. * * Returns: None. * * Side Effects: * * A call to this function can result in *ppcList (the buffer) being * reallocated and *piListLen (the max buffer size) being expanded.) */ EXPORT void list_merge(const char *pcNewList, char **ppcList, int *piListLen, int iCheck) { int offset = 0; char c, *pcScope; int initial = 0; if (!pcNewList) return; if (!ppcList) return; if (!*ppcList) { *ppcList = safe_malloc(strlen(pcNewList)+1,pcNewList,strlen(pcNewList)); *piListLen = strlen(*ppcList); return; } if (*piListLen == 0) initial = 1; /* suppresses initial comma in new lists */ if (!iCheck) { int iSLen = strlen(pcNewList); if ((iSLen + (int) strlen(*ppcList)+1) >= *piListLen) { /* too big? */ char *pcOld = *ppcList; *piListLen += iSLen + LISTINCR; *ppcList = safe_malloc(*piListLen,*ppcList,strlen(*ppcList)); SLPFree(pcOld); } if (!initial) slp_strcat(*ppcList,","); slp_strcat(*ppcList,pcNewList); return; } while((pcScope = get_next_string(",",pcNewList,&offset,&c))) { if (!list_intersection(pcScope,*ppcList)) { int iSLen = strlen(pcScope); if ((iSLen + (int) strlen(*ppcList)+1) >= *piListLen) { /* too big? */ char *pcOld = *ppcList; *piListLen += iSLen + LISTINCR; *ppcList = safe_malloc(*piListLen,*ppcList,strlen(*ppcList)); SLPFree(pcOld); } if (initial != 1) slp_strcat(*ppcList,","); /* supress initial comma */ slp_strcat(*ppcList,pcScope); /* append the scope not already on list */ } SLPFree(pcScope); } }
main() { /* Declarations Start */ status_code SC; boolean boolval; FILE *fp; employee_type *emp_ptr,*ptr; employee_type *list1,*list2,*list3; employee_type *duplicate; empname_type *name_ptr,*ptr_name; char dumbo[2]; char emp_name[NAME_LEN]; char proj_name[NAME_LEN]; char c; unsigned int Hrs; unsigned int emp_salary; char emp_address[ADD_LEN]; unsigned long int phone; int option,contnue; int numRecords,maxNumHrs; /* Declarations End */ /* Initialisations Start */ emp_ptr=NULL; name_ptr=NULL; ptr_name=NULL; ptr=NULL; list1=NULL; list2=NULL; list3=NULL; duplicate=NULL; fp=NULL; /* Initialisations End */ /* Start Reading Data from File */ fp=fopen("record.txt","a"); fclose(fp); fp=fopen("record.txt","r"); while((c=getc(fp)) != EOF) { fseek(fp,-sizeof(char),1); fscanf(fp,"%s %s %u %u %s %lu",emp_name,proj_name,&Hrs,&emp_salary,emp_address,&phone); SC=insert(&emp_ptr,emp_name,proj_name,Hrs,emp_salary,emp_address,phone); } fclose(fp); fp=NULL; /* End Reading Data from File */ do { /* Asking for Option */ puts("ENTER the option as per the operation you want to do. ENTER :-\n"); puts("1- insert/update\n2- delete\n3- getNumRecords\n4- isEmpty\n5- List_Unique\n6- getMaxNumHrs\n7- list_union\n8- list_intersection\n9- list_difference\n10- list_symmetric_difference\n"); printf("Your Choice is:- "); scanf("%d",&option); printf("\n\n"); switch (option) { /* INSERT/UPDATE */ case 1: { printf("***********INSERT**********\n\n"); /* Data Entering Start */ printf("Enter Employee Name :-\t"); gets(dumbo); gets(emp_name); remove_space_make_uppercase(emp_name); printf("Enter Employee's Project Name :-\t"); gets(proj_name); remove_space_make_uppercase(proj_name); printf("Enter Number of Hours :-\t"); scanf("%u",&Hrs); printf("Enter Employee's Salary :-\t"); scanf("%u",&emp_salary); printf("Enter Employee's Address :-\t"); gets(dumbo); gets(emp_address); remove_space_make_uppercase(emp_address); printf("Enter Employee's Phone Number :-\t"); scanf("%lu",&phone); /* Data Entering End */ /* Inserting/Updating Data */ SC=insert(&emp_ptr,emp_name,proj_name,Hrs,emp_salary,emp_address,phone); if(SC==SUCCESS) { puts("\n**********Data inserted**********\n"); } else { puts("\n**********Data insertion failed**********\n"); } break; } /* DELETE */ case 2: { printf("***********DELETE**********\n\n"); /* Data Entering Start */ printf("Enter Employee Name :-\t"); gets(dumbo); gets(emp_name); remove_space_make_uppercase(emp_name); printf("Enter Employee's Project Name :-\t"); gets(proj_name); remove_space_make_uppercase(proj_name); /* Data Entering End */ /* Deleting Data */ SC=delete_entry(&emp_ptr,emp_name,proj_name); if(SC==SUCCESS) { puts("\n**********Data deleted**********\n"); } else { puts("\n**********Data deletion failed**********\n"); } break; } /* getNumRecords */ case 3: { printf("***********getNumRecords**********\n\n"); numRecords=getNumRecords(emp_ptr); printf("\n\nNumber of ACTIVE record in the list is :- %d",numRecords); break; } /* isEmpty */ case 4: { printf("***********isEmpty**********\n\n"); boolval=isEmpty(emp_ptr); if(boolval==NO) { puts("The list is NOT EMPTY"); } else { puts("The list is EMPTY"); } break; } /* list_unique */ case 5: { printf("***********list_unique**********\n\n"); /* Creating Duplicate Entries for Testing */ duplicate=create_duplicate(); list_unique(duplicate); printf("\n\n*****LIST MADE UNIQUE*****\n\n"); print(duplicate); freeof_employee(&duplicate); break; } /* getMaxNumHrs */ case 6: { printf("***********getMaxNumHrs**********\n\n"); /* Data Entering Start */ printf("Enter Project Name :-\t"); gets(dumbo); gets(proj_name); remove_space_make_uppercase(proj_name); /* Data Entering End */ maxNumHrs=getMaxNumHrs(emp_ptr,proj_name,&name_ptr); printf("\nMaximum hours spent in the given project is :- %d\n\n",maxNumHrs); if(maxNumHrs!=0) { printf("Employee's spending maximum hours in this project are :-\n"); ptr_name=name_ptr; while(ptr_name!=NULL) { puts(ptr_name->employee_name); ptr_name=ptr_name->next; } } freeof_empname(&name_ptr); ptr_name=NULL; break; } /* list_union */ case 7: { printf("***********list_union**********\n\n"); /* Creating list1 and list2 for Testing */ puts("*****Creating Testing Entries for list1*****"); list1=create_checklist(); puts("*****Creating Testing Entries for list2*****"); list2=create_checklist(); list3=list_union(list1,list2); printf("\n\n*****UNION of the given lists is as follows*****\n\n"); print(list3); freeof_employee(&list1); freeof_employee(&list2); freeof_employee(&list3); break; } /* list_intersection */ case 8: { printf("***********list_intersection**********\n\n"); /* Creating list1 and list2 for Testing */ puts("*****Creating Testing Entries for list1*****"); list1=create_checklist(); puts("*****Creating Testing Entries for list2*****"); list2=create_checklist(); list3=list_intersection(list1,list2); printf("\n\n*****INTERSECTION of the given lists is as follows*****\n\n"); print(list3); freeof_employee(&list1); freeof_employee(&list2); freeof_employee(&list3); break; } /* list_difference */ case 9: { printf("***********list_difference**********\n\n"); /* Creating list1 and list2 for Testing */ puts("*****Creating Testing Entries for list1*****"); list1=create_checklist(); puts("*****Creating Testing Entries for list2*****"); list2=create_checklist(); list3=list_difference(list1,list2); printf("\n\n*****DIFFERENCE of the given lists is as follows*****\n\n"); print(list3); freeof_employee(&list1); freeof_employee(&list2); freeof_employee(&list3); break; } /* list_symmetric_difference */ case 10: { printf("***********list_symmetric_difference**********\n\n"); /* Creating list1 and list2 for Testing */ puts("*****Creating Testing Entries for list1*****"); list1=create_checklist(); puts("*****Creating Testing Entries for list2*****"); list2=create_checklist(); list3=list_symmetric_difference(list1,list2); printf("\n\n*****SYMMETRIC DIFFERENCE of the given lists is as follows*****\n\n"); print(list3); freeof_employee(&list1); freeof_employee(&list2); freeof_employee(&list3); break; } /* Default */ default: { break; } } /* Asking for CHOICE to Continue */ puts("\n\nIf you want to continue... ? Enter 1 if YES or 0 if NO\n"); printf("Your Choice is:- "); scanf("%d",&contnue); printf("\n\n"); }while(contnue==1); /* Start Writing Data from File */ fp=fopen("record.txt","w"); ptr=emp_ptr; while(ptr!=NULL) { fprintf(fp,"%s %s %u %u %s %lu",ptr->employee_name,ptr->project_name,ptr->numHrs,ptr->employee_salary,ptr->employee_address,ptr->phone_number); ptr=ptr->next; } fclose(fp); fp=NULL; /* End Writing Data from File */ if(emp_ptr!=NULL) { print(emp_ptr); freeof_employee(&emp_ptr); } getch(); }