void TimerStartup( ) { HalInitClock(); TimerLastTime = TimeGet(); HeapInit( &TimerHeap1 ); HeapInit( &TimerHeap2 ); Timers = &TimerHeap1; TimersOverflow = &TimerHeap2; IsrRegisterHandler( TimerInterrupt, (void *) HAL_ISR_TIMER, IRQ_LEVEL_TIMER ); TimerSetNextTimer(TimerLastTime); }
int main() { LinkedListInit( & queueList ); LinkedListInit( & stackList ); AtomicListInit( & atomicList ); HeapInit( & heap ); int data; do { printf("enter a data value:\n0 to exit\n1 to remove a node\n2 to print the data structures\nor a larger number to add a node.\n"); scanf("%d", &data ); if( data == 0 ) return 0; else if( data == 1 ) Pop(); else if( data == 2 ) { printf("queue:"); DumpList( & queueList ); printf("stack:"); DumpList( & stackList ); printf("Atomic:"); DumpAtomic( &atomicList ); DumpHeap( & heap ); } else Add(data); }while( data != 0 ); return 0; }
/* initialise everything */ void PicocInitialise(Picoc *pc, int StackSize) { memset(pc, '\0', sizeof(*pc)); PlatformInit(pc); BasicIOInit(pc); HeapInit(pc, StackSize); TableInit(pc); VariableInit(pc); LexInit(pc); TypeInit(pc); #ifndef NO_HASH_INCLUDE IncludeInit(pc); #endif LibraryInit(pc); #ifdef BUILTIN_MINI_STDLIB LibraryAdd(pc, &pc->GlobalTable, "c library", &CLibrary[0]); CLibraryInit(pc); #endif PlatformLibraryInit(pc); DebugInit(pc); }
void kmain( void* mdb,u32i magic ) { if( magic != 0x2BADB002 ) { while(1); } InitDescriptorTables(); VideoInit(); SetColor(BLACK,BRIGHT_WHITE); KPrintf("This is Atomic Kernel 12715A\n"); KPrintf("Starting Timer..."); InitTimer(100); KPrintf("Done.\n"); KPrintf("Starting Keyboard..."); InitKeyboard(); KPrintf("Done.\n"); KPrintf("Starting Paging..."); InitialisePaging(); KPrintf("Done.\n"); KPrintf("Starting Heap..."); HeapInit(); KPrintf("Done.\n"); u32i *A,*B,*C; A = Kmalloc(8); B = Kmalloc(8); KPrintf("A:%x,B:%x",A,B); KFree(A); KFree(B); C = Kmalloc(16); KPrintf("C:%x\n",C); while(1); }
static void ThreadStateInit(ThreadState* self, BuildQueue* queue, size_t heap_size, size_t scratch_size, int index) { HeapInit(&self->m_LocalHeap, heap_size, HeapFlags::kDefault); LinearAllocInit(&self->m_ScratchAlloc, &self->m_LocalHeap, scratch_size, "thread-local scratch"); self->m_ThreadIndex = index; self->m_Queue = queue; }
void Initialization(int n) { int i; EdgeInit(n); HeapInit(n); for(i=1;i<=n;i++) { Key[i]=INF; Parant[i]=NIL; } }
void Compute() { UFSetInit(); HeapInit(); int count = 0; while (count < mGraph->NumVertex() - 1 && mHeap.size() > 0) { const EdgeType* minEdge = HeapExtract(); if (UFSetUnion(minEdge->u, minEdge->v)) { mTotalWeight += minEdge->weight; ++count; } } }
void DigestCacheInit(DigestCache* self, size_t heap_size, const char* filename) { ReadWriteLockInit(&self->m_Lock); self->m_State = nullptr; self->m_StateFilename = filename; HeapInit(&self->m_Heap, heap_size, HeapFlags::kDefault); LinearAllocInit(&self->m_Allocator, &self->m_Heap, heap_size / 2, "digest allocator"); MmapFileInit(&self->m_StateFile); HashTableInit(&self->m_Table, &self->m_Heap, HashTable::kFlagPathStrings); self->m_AccessTime = time(nullptr); MmapFileMap(&self->m_StateFile, filename); if (MmapFileValid(&self->m_StateFile)) { const DigestCacheState* state = (const DigestCacheState*) self->m_StateFile.m_Address; if (DigestCacheState::MagicNumber == state->m_MagicNumber) { const uint64_t time_now = time(nullptr); // Throw out records that haven't been accessed in a week. const uint64_t cutoff_time = time_now - 7 * 24 * 60 * 60; self->m_State = state; //HashTablePrepareBulkInsert(&self->m_Table, state->m_Records.GetCount()); for (const FrozenDigestRecord& record : state->m_Records) { if (record.m_AccessTime < cutoff_time) continue; DigestCacheRecord* r = LinearAllocate<DigestCacheRecord>(&self->m_Allocator); r->m_Hash = record.m_FilenameHash; r->m_ContentDigest = record.m_ContentDigest; r->m_Next = nullptr; r->m_String = record.m_Filename.Get(); r->m_Timestamp = record.m_Timestamp; r->m_AccessTime = record.m_AccessTime; HashTableInsert(&self->m_Table, r); } Log(kDebug, "digest cache initialized -- %d entries", state->m_Records.GetCount()); } else { MmapFileUnmap(&self->m_StateFile); } } }
void HeapSort(int arr[], int n, PriorityComp pc) { Heap heap; int i; HeapInit(&heap, pc); // 정렬 대상을 가지고 힙을 구성한다. for(i=0; i<n; i++) HInsert(&heap, arr[i]); // 순서대로 하나씩 꺼내서 정렬을 완성한다. for(i=0; i<n; i++) arr[i] = HDelete(&heap); }
/* initialise everything */ void PicocInitialise(int StackSize) { BasicIOInit(); HeapInit(StackSize); TableInit(); VariableInit(); LexInit(); TypeInit(); #ifndef NO_HASH_INCLUDE IncludeInit(); #endif LibraryInit(); #ifdef BUILTIN_MINI_STDLIB LibraryAdd(&GlobalTable, "c library", &CLibrary[0]); CLibraryInit(); #endif PlatformLibraryInit(); }
void __cdecl ldr_logo() { kboot_info *bi; unsigned char ch; UINT32 e; HeapInit(); ConsoleInit(); TxtSetFlags(BGCOLOR_BLACK|FGCOLOR_GREEN); TxtClearScreen(); SerialInit(); PicInit(); DescriptorsInit(); InterruptsInit(); ExceptionsInit(); DbgInit(); _enable(); IrqInit(); TssInit(); Vm86Init(); TimerInit(); KbdInit(); //DbgStepEnable(); StorageProbe(); e = VolReadFile("A:\\OSLDR.EXE", (VPTR)0x300000); DbgPrintf("%s\n", DbgStatusStr(e)); if(VideoInit()) { DbgPrintf("\nError Initializing Video Subsystem"); } while(1) { ch=KbdGetKey(); _Putch(ch); if(ch==33) KbdCpuReset(); } while(1); }
// The main function. int main(void) { int i=0, idx=0, tmp; int num[100]; /* The numbers to input */ /* Creating a heap, and initializing it */ struct _HeapStruct heap; HeapInit(&heap); while(1) { scanf("%d", &tmp); if(tmp == -1) break; num[idx++] = tmp; insert_array(&heap, tmp); } buildHeap(&heap); print(&heap); return 0; }
uint32_t init_mem() { HeapInit((void*)(( (uint32_t)(&_heap_start) + 8) & 0xFFFFFFFC), ((uint32_t)(&_heap_size) -8) & 0xFFFFFFFC); return 0; }
void fileKMerge( Data *run_devices, const int k, Data *output_device ) { SPD_ASSERT( output_device->medium == File || output_device->medium == Array, "output_device must be pre-allocated!" ); /* Memory buffer */ Data buffer; DAL_init( &buffer ); DAL_allocBuffer( &buffer, DAL_allowedBufSize() ); const dal_size_t bufferedRunSize = DAL_dataSize(&buffer) / (k + 1); //Size of a single buffered run (+1 because of the output buffer) /* TODO: Handle this case */ SPD_ASSERT( bufferedRunSize > 0 , "fileKMerge function doesn't allow a number of runs greater than memory buffer size" ); /* Runs Buffer */ int* runs = buffer.array.data; /* Output buffer */ int* output = buffer.array.data+k*bufferedRunSize; /* Indexes and Offsets for the k buffered runs */ dal_size_t *run_indexes = (dal_size_t*) calloc( sizeof(dal_size_t), k ); dal_size_t *run_offsets = (dal_size_t*) malloc( k * sizeof(dal_size_t) ); dal_size_t *run_buf_sizes = (dal_size_t*) malloc( k * sizeof(dal_size_t) ); /* The auxiliary heap struct */ Heap heap; HeapInit( &heap, k ); dal_size_t j; /* Initializing the buffered runs and the heap */ for ( j=0; j < k; j++ ) { run_buf_sizes[j] = DAL_dataCopyOS( &run_devices[j], 0, &buffer, j*bufferedRunSize, MIN(bufferedRunSize, DAL_dataSize(&run_devices[j])) ); run_offsets[j] = run_buf_sizes[j]; HeapPush( &heap, runs[j*bufferedRunSize], j ); } /* Merging the runs */ dal_size_t outputSize = 0; dal_size_t outputOffset = 0; dal_size_t i; for ( i=0; i<DAL_dataSize(output_device); i++ ) { Min_val min = HeapTop( &heap ); HeapPop( &heap ); //the run index j = min.run_index; dal_size_t remainingSize = DAL_dataSize(&run_devices[j])-run_offsets[j]; if ( ++(run_indexes[j]) < run_buf_sizes[j] ) //If there are others elements in the buffered run HeapPush( &heap, runs[j*bufferedRunSize+run_indexes[j]], j ); //pushes a new element in the heap else if ( remainingSize > 0 ) { //else, if the run has not been read completely run_buf_sizes[j] = DAL_dataCopyOS( &run_devices[j], run_offsets[j], &buffer, j*bufferedRunSize, MIN(remainingSize, bufferedRunSize) ); run_offsets[j] += run_buf_sizes[j]; run_indexes[j] = 0; HeapPush( &heap, runs[j*bufferedRunSize], j ); } output[outputSize++] = min.val; if ( outputSize == bufferedRunSize || i==DAL_dataSize(output_device)-1 ) { //If the output buffer is full outputOffset += DAL_dataCopyOS( &buffer, k*bufferedRunSize, output_device, outputOffset, outputSize ); outputSize = 0; } } /* Freeing memory */ HeapDestroy( &heap ); DAL_destroy( &buffer ); free( run_indexes ); free( run_offsets ); free( run_buf_sizes ); }